Skip to content

fix/colab causal repro notebook#6

Merged
DaviBonetto merged 3 commits intomainfrom
codex/fix/colab-causal-repro-notebook
Mar 18, 2026
Merged

fix/colab causal repro notebook#6
DaviBonetto merged 3 commits intomainfrom
codex/fix/colab-causal-repro-notebook

Conversation

@DaviBonetto
Copy link
Copy Markdown
Owner

@DaviBonetto DaviBonetto commented Mar 18, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed corrupted multilingual Desktop path detection in repository root candidate list.
  • New Features

    • Enhanced causal intervention with improved rho clamping logic and optimized forward path execution including iterative constraint validation.
  • Tests

    • Added comprehensive test coverage for rho computations, discrete array clamping, and constraint validation workflows.

Use the measured per-channel rho as the no-op gate and add a second correction pass when the analytic floor is not enough. This keeps the clamp aligned with the actual model metric so the all_layer Colab run does not fail on later layers.
Clamp the Mamba recurrence at the discrete_A level instead of rewriting dt. This aligns the intervention with the paper equation and preserves the input-dependent B term so near-no-op targets like rho=0.99 do not collapse accuracy.

Add coverage for token-wise discrete_A scaling so the clamp stays a no-op below target and respects the sanity check above target.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5da13602-37d9-4f18-8f5c-95d2c3edc432

📥 Commits

Reviewing files that changed from the base of the PR and between d2e6b23 and 69de033.

📒 Files selected for processing (3)
  • notebooks/06_Causal_Intervention_Reproduction.ipynb
  • scripts/run_causal_intervention.py
  • tests/test_run_causal_intervention.py

📝 Walkthrough

Walkthrough

The pull request replaces the forward-hook-based clamping mechanism with a patched forward-path approach in the causal intervention script. New helper functions compute and clamp discrete-A parameters, and the clamping logic now applies iterative refinement during the forward pass. A corrupted file path in a notebook is also corrected.

Changes

Cohort / File(s) Summary
Notebook Path Correction
notebooks/06_Causal_Intervention_Reproduction.ipynb
Fixed corrupted "?rea de Trabalho" path candidate by replacing it with two corrected multilingual variants ("Área de Trabalho" and "Area de Trabalho").
Core Clamping Refactor
scripts/run_causal_intervention.py
Introduced _compute_discrete_a_rho() and _clamp_discrete_a_to_target() helper functions for discrete-A-based clamping. Refactored _clamp_dt_to_target() with iterative correction logic (up to 3 iterations) to refine overshooting rho values. Added _mamba_slow_forward_with_clamp() to execute the forward pass with integrated clamping. Reworked apply_clamp_hooks() from hook-based to patched-forward approach with restoration callbacks. Updated evaluate_accuracy() cleanup to use restoration calls.
Test Coverage
tests/test_run_causal_intervention.py
Added test cases for _compute_discrete_a_rho(), _clamp_discrete_a_to_target(), and dt clamping follow-up correction behavior. Exposed helper functions in module imports for testing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hooks gave way to patches fine,
Discrete A now in full design,
Clamping flows with iterative care,
Rho balanced everywhere—
Forward paths so clean and bright!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix/colab-causal-repro-notebook
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DaviBonetto DaviBonetto merged commit f7226e4 into main Mar 18, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant