Centralize soft-cap logic behind shared helper and named sentinel#1490
Closed
hiro-nikaitou wants to merge 2 commits into
Closed
Centralize soft-cap logic behind shared helper and named sentinel#1490hiro-nikaitou wants to merge 2 commits into
hiro-nikaitou wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- isort: fix import ordering in bridge.py, HookedTransformer.py - black: reformat conditional expression in HookedTransformer.py - black: wrap long import line in hooked_transformer_config.py Format check commands all pass locally (pycln, isort, black).
Collaborator
|
Hi @hiro-nikaitou! Thank you for taking the time to work on this, unfortunately another user submitted a competing PR that included some elements you were missing here, and we have chosen to go with that implementation. Closing this PR, let me know if there are any other issues you're interested in taking on and I can get you assigned! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1489
Summary
This PR centralizes the duplicated
cap * tanh(x / cap)soft-cap logic into a shared helper functionapply_softcapwith a named sentinelSOFTCAP_DISABLED, as proposed in issue #1489.Changes
apply_softcap(x, cap)helper andSOFTCAP_DISABLED = -1.0constant totransformer_lens/utilities/activation_functions.pyapply_softcap:transformer_lens/components/abstract_attention.py(attention score soft-cap)transformer_lens/HookedTransformer.py(output logit soft-cap)transformer_lens/model_bridge/sources/native/model.py(both attention score and output logit soft-caps)-1.0withSOFTCAP_DISABLEDin config defaults andgetattrfallbackVerification
apply_softcapreturnsxunchanged whencap <= 0(disabled)apply_softcapcomputescap * tanh(x / cap)whencap > 0(enabled)