Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated drift compensation mechanism to use is_perfect=True when determining the reference readout #674

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/aihwkit/simulator/tiles/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def init_mapping_scales(self) -> None:
self.set_mapping_scales(mapping_scales)

@no_grad()
def _forward_drift_readout_tensor(self, reset_if: bool = False) -> Optional[Tensor]:
def _forward_drift_readout_tensor(self, reset_if: bool = False, is_perfect=False) -> Optional[Tensor]:
"""Perform a forward pass using the drift read-out tensor.

Args:
Expand Down Expand Up @@ -126,9 +126,16 @@ def _forward_drift_readout_tensor(self, reset_if: bool = False) -> Optional[Tens

# We need to take the bias as a common column here, also we do
# not want to use indexed.
return self.tile.forward(
is_perfect_state = self.rpu_config.forward.is_perfect
tile_rpu_config = self.rpu_config
tile_rpu_config.forward.is_perfect = True
self.tile.set_config(tile_rpu_config)
output = self.tile.forward(
self.drift_readout_tensor, False, self.in_trans, self.out_trans, True, self.non_blocking
)
tile_rpu_config.forward.is_perfect = is_perfect_state
self.tile.set_config(tile_rpu_config)
return output

@no_grad()
def program_weights(
Expand Down Expand Up @@ -184,7 +191,7 @@ def program_weights(
hasattr(self.rpu_config, "drift_compensation")
and self.rpu_config.drift_compensation is not None
):
forward_output = self._forward_drift_readout_tensor(True)
forward_output = self._forward_drift_readout_tensor(True, is_perfect=True)
self.drift_baseline = self.rpu_config.drift_compensation.init_baseline(forward_output)

@no_grad()
Expand Down