fix: prevent UnboundLocalError when analyzer is not initialized (#301)
* fix: prevent UnboundLocalError when analyzer is not initialized Move cleanup of analyzer and residuals inside the conditional block where they are actually defined to avoid crashing when --print-residual-geometry or --plot-residuals are not used. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: address AI review feedback on residual cleanup --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+4
-2
@@ -443,6 +443,9 @@ def run():
|
|||||||
|
|
||||||
if settings.plot_residuals:
|
if settings.plot_residuals:
|
||||||
analyzer.plot_residuals()
|
analyzer.plot_residuals()
|
||||||
|
|
||||||
|
# We don't need the full residuals after computing their means and analyzing geometry.
|
||||||
|
del good_residuals, bad_residuals, analyzer
|
||||||
else:
|
else:
|
||||||
print("* Obtaining residual mean for good prompts...")
|
print("* Obtaining residual mean for good prompts...")
|
||||||
good_means = model.get_residuals_mean(good_prompts)
|
good_means = model.get_residuals_mean(good_prompts)
|
||||||
@@ -462,8 +465,7 @@ def run():
|
|||||||
)
|
)
|
||||||
refusal_directions = F.normalize(refusal_directions, p=2, dim=1)
|
refusal_directions = F.normalize(refusal_directions, p=2, dim=1)
|
||||||
|
|
||||||
# We don't need the residuals after computing refusal directions.
|
# Clear cache before starting the optimization study.
|
||||||
del good_residuals, bad_residuals, analyzer
|
|
||||||
empty_cache()
|
empty_cache()
|
||||||
|
|
||||||
trial_index = 0
|
trial_index = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user