Skip to content

Commit c304749

Browse files
committed
Update steering.py
1 parent 335b900 commit c304749

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

optillm/autothink/steering.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,14 @@ def __call__(self, module, input_tensors, output):
303303
# Keep strength within safe bounds
304304
safe_strength = min(max(strength, 0.1), 2.0)
305305

306-
# Log when pattern changes
306+
# Log when pattern changes or is applied
307307
if pattern != self.last_pattern:
308-
logger.info(f"Switching to {pattern} reasoning pattern with strength {safe_strength}")
308+
logger.info(f"[STEERING ACTIVATED] Switching to {pattern} reasoning pattern with strength {safe_strength}")
309309
self.last_pattern = pattern
310+
else:
311+
# Log periodically that steering is still active (every ~20 tokens)
312+
if random.random() < 0.05:
313+
logger.info(f"[STEERING ACTIVE] Applying {pattern} pattern with strength {safe_strength}")
310314

311315
# Apply the steering vector
312316
try:
@@ -478,6 +482,11 @@ def _try_token_match(self) -> bool:
478482
'is_partial': True
479483
}
480484

485+
# Log token history periodically
486+
if random.random() < 0.01:
487+
history_sample = self.token_history[-5:] if len(self.token_history) >= 5 else self.token_history
488+
logger.debug(f"Token matching with history (last {len(history_sample)} of {len(self.token_history)} tokens): {history_sample}")
489+
481490
# Check for matches in tokenized contexts
482491
for tokenized_context, vector in self.manager.tokenized_contexts.items():
483492
token_list = list(tokenized_context)
@@ -519,7 +528,12 @@ def _try_token_match(self) -> bool:
519528
self.match_found = True
520529
self.current_vector = best_match['vector']
521530
pattern = best_match['vector'].get("reasoning_pattern", "unknown")
522-
logger.info(f"Found {match_type} token match ({best_match['match_len']}/{best_match['token_len']} tokens) for {pattern} pattern")
531+
pivot_token = best_match['vector'].get("pivot_token", "")
532+
533+
logger.info(f"[STEERING MATCH FOUND] {match_type} token match for '{pattern}' pattern")
534+
logger.info(f"[STEERING DETAILS] Match quality: {best_match['match_len']}/{best_match['token_len']} tokens")
535+
logger.info(f"[STEERING DETAILS] Pivot token: '{pivot_token}'")
536+
523537
return True
524538

525539
return False

0 commit comments

Comments
 (0)