Open dtch1997 opened 1 month ago
The issue is that there are 2 yield statements in SteeringHook::__call__()
. A contextmanager can only yield once before exiting. It looks like the intention is that if the multiplier is 0, to just yield
, but the bug arises because the code continues and hits the second yield
statement. This can be solved by adding an else:
statement after the first yield
, to ensure that only one yield
runs. E.g.:
# multiplier 0 is equivalent to no steering, so just skip patching in that case
if self.config.multiplier == 0:
yield
else:
handle = layer_sv.patch_activations(
model=context.pipeline.model,
layer_config=self.config.layer_config,
multiplier=self.config.multiplier,
min_token_index=min_token_index,
operator=get_patch_operator(self.config.patch_operator),
)
yield
Weird error involving context managers that I don't fully understand
To reproduce:
Stack trace: