feat: add RWKV-7 (Goose) TransformerBridge adapter (RWKV7ForCausalLM)#1521
Conversation
|
@jlarson4 ready for review |
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
7835baf to
ea4e0c2
Compare
|
Same note about reviewing the failing CI checks here @mukund1985. Thanks for taking both of these adapters on! |
|
@mukund1985 Very similar comment here as on #1520. We cannot use the SSM-based components for non-SSM recurrent architectures. I recommend adopting the same |
…ge base class Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
…7 attn/ffn sublayers Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
|
Thanks for the review. Both points addressed in the latest commits:
|
Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
|
@jlarson4 all CI checks are now green — ready for your re-review when you get a chance. |
|
Looks great, thanks @mukund1985! Merging now |
… entry Brings in the RWKV-7 additions from TransformerLensOrg#1521 that landed in dev: - _bridge_builder.py: added RWKV-7 passthrough attrs (num_heads, value_dim, decay/gate/a/v_low_rank_dim, norm_first, norm_bias, fuse_norm, attn_mode, hidden_act) - generate_report.py: added RWKV7ForCausalLM description entry Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
* Add RavenForCausalLM (Huginn) TransformerBridge adapter Adds a TransformerBridge architecture adapter for RavenForCausalLM (tomg-group-umd/huginn-0125), a depth-recurrent decoder with a prelude / weight-tied recurrent core / coda structure, resolving #1469. - raven.py delegates the recurrence to the remote-code HF forward and maps the three physical block lists (prelude / core_block / coda) via SSMBlockBridge, with combined-QKV native attention and a gated MLP. Sets applicable_phases=[] (a random initial latent state and post-residual sandwich norms diverge from the verify_models phases) and supports_fold_ln=False (ln_f is reused mid-network). prepare_loading patches Huginn's remote code for transformers v5 (tied-weights-keys dict form + a weight re-init guard). - Registers in the adapter factory, the model registry (canonical author and description) and supported_models.json; surfaces the recurrence-shape config via both _HF_PASSTHROUGH_ATTRS lists. - Adds synthetic-config unit tests and CI-gated integration tests. * fix: pass num_steps as int to iterate_forward (0-d tensor has no len) * fix: remove unused torch import and use setattr for dynamic cfg attrs * style: apply black formatting to raven.py Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> * refactor: introduce OpaqueBlockBridge; use it for Raven instead of SSMBlockBridge Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> * style: apply black formatting to opaque_block, ssm_block, __init__ Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> * style: fix import order in generalized_components/__init__.py (isort) Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> * fix: strip dead hook_q/k/v aliases from Raven AttentionBridge Raven uses a combined Wqkv projection (no separate q/k/v submodules), so AttentionBridge's default hook_q/hook_k/hook_v aliases (which target q.hook_out / k.hook_out / v.hook_out) are unresolvable. The upstream test_every_hook_alias_resolves_to_hookpoint audit catches these as 9 dead aliases across prelude / core_block / coda. Strip them by setting an instance-level hook_aliases that omits those three keys, leaving only the aliases that have real HookPoint targets. Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> * chore: merge upstream/dev — add RWKV-7 passthrough attrs and registry entry Brings in the RWKV-7 additions from #1521 that landed in dev: - _bridge_builder.py: added RWKV-7 passthrough attrs (num_heads, value_dim, decay/gate/a/v_low_rank_dim, norm_first, norm_bias, fuse_norm, attn_mode, hidden_act) - generate_report.py: added RWKV7ForCausalLM description entry Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com> --------- Signed-off-by: Mukund Pandey <mukund.pandey@gmail.com>
Closes #1462.
Adds a TransformerBridge adapter for
RWKV7ForCausalLM(RWKV-7 "Goose") fromfla-org/flash-linear-attention, loaded viatrust_remote_code=True.Architecture overview
RWKV-7 is an attention-free recurrent model:
Each
RWKV7Blockcontains:attn_norm— standard biased LayerNorm (NOT RMSNorm)attn—RWKV7Attention: generalized delta-rule time-mixing with matrix-valued state; 4-tuple return(y, v_first, state, ...)ffn_norm— fused add-and-norm whenfuse_norm=True(default)ffn—RWKV7FeedForward: token-shift + sqrelu channel-mixing (not a gated MLP)v_first(cross-block state) is managed internally byRWKV7Model.forward— no adapter handling required.Adapter decisions
SSMBlockBridgeformodel.layers— delegates the whole recurrent block; exposeshook_in/hook_outon the residual stream.BlockBridgeis not usable: its hook aliases hardcode a standard pre-norm flow that RWKV-7 does not follow.SSM2MixerBridgefor bothattnandffnsublayers — tuple-aware passthrough that correctly preservesattn's 4-tuple return (carryingv_first) andffn's 2-tuple return without re-implementing either.NormalizationBridge(biased LayerNorm) forattn_normandln_final—uses_rms_norm=False,normalization_type="LN".ffn_normas plainGeneralizedComponent— whenfuse_norm=True, the block callsffn_norm(hidden_states, residual, True), a fused 3-arg signature thatNormalizationBridge's single-input contract cannot express.head_dimexcluded from_HF_PASSTHROUGH_ATTRS— read-only property onTransformerBridgeConfig(alias ofd_head); a passthroughsetattrwould crash boot.applicable_phases = []— correctness covered by integration tests.prepare_loadingmirrors Raven's transformers v5 guards (_tied_weights_keyslist→dict,_init_weightsre-randomization guard), applied defensively viatry/except.Files changed
transformer_lens/model_bridge/supported_architectures/rwkv7.pytests/unit/model_bridge/supported_architectures/test_rwkv7_adapter.pytests/integration/model_bridge/test_rwkv7_adapter.pyslow+skipif(CI)+importorskip("fla"))transformer_lens/model_bridge/supported_architectures/__init__.pyRWKV7ArchitectureAdaptertransformer_lens/factories/architecture_adapter_factory.pyRWKV7ForCausalLMtransformer_lens/tools/model_registry/__init__.pyHF_SUPPORTED_ARCHITECTURES+CANONICAL_AUTHORS_BY_ARCHtransformer_lens/tools/model_registry/generate_report.pytransformer_lens/model_bridge/sources/_bridge_builder.pyTesting
Unit tests (31) pass on synthetic config — no HF Hub access:
Integration tests require
flash-linear-attention(~191 MB checkpoint download):