コード例 #1
0
def get_tile_for_plotting(rpu_config: SingleRPUConfig,
                          n_traces: int,
                          use_cuda: bool = False,
                          noise_free: bool = False) -> BaseTile:
    """Returns an analog tile for plotting the response curve.

    Args:
        rpu_config: RPU Configuration to use for plotting
        n_traces: Number of traces to plot
        use_cuda: Whether to use the CUDA implementation (if available)
        noise_free: Whether to turn-off cycle-to-cycle noises

    Returns:
        Instantiated tile.
    """
    config = deepcopy(rpu_config)

    # Make sure we use single pulses for the overview.
    config.update.update_bl_management = False
    config.update.update_management = False
    config.update.desired_bl = 1

    if noise_free:
        config.forward.is_perfect = True

        config.device.dw_min_std = 0.0  # Noise free.
        if (hasattr(config.device, 'write_noise_std')
                and getattr(config.device, 'write_noise_std') > 0.0):
            # Just make very small to avoid hidden parameter mismatch.
            setattr(config.device, 'write_noise_std', 1e-6)

    analog_tile = AnalogTile(n_traces, 1, config)  # type: BaseTile
    analog_tile.set_learning_rate(1)
    weights = config.device.as_bindings().w_min * ones((n_traces, 1))
    analog_tile.set_weights(weights)

    if use_cuda and cuda.is_compiled():
        return analog_tile.cuda()
    return analog_tile
コード例 #2
0
ファイル: visualization.py プロジェクト: maljoras/aihwkit
def get_tile_for_plotting(rpu_config: Union[SingleRPUConfig,
                                            UnitCellRPUConfig],
                          n_traces: int,
                          use_cuda: bool = False,
                          noise_free: bool = False) -> BaseTile:
    """Return an analog tile for plotting the response curve.

    Args:
        rpu_config: RPU Configuration to use for plotting
        n_traces: Number of traces to plot
        use_cuda: Whether to use the CUDA implementation (if available)
        noise_free: Whether to turn-off cycle-to-cycle noises (if possible)

    Returns:
        Instantiated tile.
    """
    def set_noise_free(dev: Any) -> Any:
        if hasattr(dev, 'dw_min_std'):
            dev.dw_min_std = 0.0  # Noise free.

        if hasattr(dev, 'refresh_forward'):
            setattr(dev, 'refresh_forward', IOParameters(is_perfect=True))

        if hasattr(dev, 'refresh_update'):
            setattr(dev, 'refresh_update',
                    UpdateParameters(pulse_type=PulseType.NONE))

        if hasattr(dev, 'transfer_forward'):
            setattr(dev, 'refresh_forward', IOParameters(is_perfect=True))

        if hasattr(dev, 'transfer_update'):
            setattr(dev, 'transfer_update',
                    UpdateParameters(pulse_type=PulseType.NONE))

        if (hasattr(dev, 'write_noise_std')
                and getattr(dev, 'write_noise_std') > 0.0):
            # Just make very small to avoid hidden parameter mismatch.
            setattr(dev, 'write_noise_std', 1e-6)

    config = deepcopy(rpu_config)

    # Make sure we use single pulses for the overview.
    config.update.update_bl_management = False
    config.update.update_management = False
    config.update.desired_bl = 1

    if noise_free:
        config.forward.is_perfect = True

        set_noise_free(config.device)
        if hasattr(config.device, 'unit_cell_devices'):
            for dev in getattr(config.device, 'unit_cell_devices'):
                set_noise_free(dev)
        if hasattr(config.device, 'device'):
            set_noise_free(getattr(config.device, 'device'))

    analog_tile = AnalogTile(n_traces, 1, config)  # type: BaseTile
    analog_tile.set_learning_rate(1)
    w_min = getattr(config.device.as_bindings(), 'w_min', -1.0)

    weights = w_min * ones((n_traces, 1))
    analog_tile.set_weights(weights)

    if use_cuda and cuda.is_compiled():
        return analog_tile.cuda()
    return analog_tile