def test_hidden_parameter_mismatch(self): """Test for error if tile structure mismatches.""" model = self.get_layer() state_dict = model.state_dict() # Create the device and the array. rpu_config = SingleRPUConfig( device=LinearStepDevice() # different hidden structure ) new_model = self.get_layer(rpu_config=rpu_config) if new_model.analog_tile.__class__.__name__ != model.analog_tile.__class__.__name__: with self.assertRaises(TileError): self.assertRaises(new_model.load_state_dict(state_dict))
def get_rpu_config(self): return SingleRPUConfig( device=LinearStepDevice(w_max_dtod=0, w_min_dtod=0))
from aihwkit.simulator.rpu_base import cuda # Prepare the datasets (input and expected output). x = Tensor([[0.1, 0.2, 0.4, 0.3], [0.2, 0.1, 0.1, 0.3]]) y = Tensor([[1.0, 0.5], [0.7, 0.3]]) # Define a single-layer network, using a vector device having multiple # devices per crosspoint. Each device can be arbitrarily defined rpu_config = UnitCellRPUConfig() # 3 arbitrary devices per cross-point. rpu_config.device = VectorUnitCell( unit_cell_devices=[ ReferenceUnitCell(unit_cell_devices=[SoftBoundsDevice(w_max=1.0)]), ConstantStepDevice(), LinearStepDevice(w_max_dtod=0.4), SoftBoundsDevice() ]) # Only one of the devices should receive a single update. # That is selected randomly, the effective weights is the sum of all # weights. rpu_config.device.update_policy = VectorUnitCellUpdatePolicy.SINGLE_RANDOM model = AnalogLinear(4, 2, bias=True, rpu_config=rpu_config) print(rpu_config) # Move the model and tensors to cuda if it is available. if cuda.is_compiled():