Skip to content

Add SenseNova-Loop-9B (looped transformer + mHC routing) - #2079

Open
yunlistener wants to merge 1 commit into
ml-explore:mainfrom
yunlistener:add-sensenova-loop
Open

yunlistener wants to merge 1 commit into
ml-explore:mainfrom
yunlistener:add-sensenova-loop

Conversation

@yunlistener

Copy link
Copy Markdown

Requirements

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: Model port drafted with AI assistance (Hermes agent with Qwen2.8-27B-6bit model run on Mac Studio) , reviewed and verified line by line by myself

Model information

Supported checkpoints

Verification

Run mlx-lm command:

mlx_lm.generate --model SenseNova-Loop-9B-6bit -p "The secret to baking a good cake is" -m 300

Output:

The secret to baking a good cake is a combination of several key factors:

**Precision & Measurement**
- Use a kitchen scale for accuracy. Baking is chemistry, and even small
  imprecisions can throw off the balance.
- Measure ingredients by weight rather than volume when possible.

**Room-Temperature Ingredients**
- Let butter, eggs, and milk come to room temperature. This helps with
  emulsification and even mixing.

**Fresh Leavening**
- Use fresh baking powder, baking soda, or yeast. Old leavening agents
  won't activate properly.

**Don't Overmix**
- Mix just until combined. Overmixing develops gluten, leading to a tough,
  dense crumb.

**Patience**
- Bake at the right temperature. Too hot can cause cracking or a gummy center.
- Test doneness with a toothpick rather than relying solely on time.

**Quality Ingredients**
- Use good butter

Prompt: 18 tokens, 57.528 tokens-per-sec
Generation: 300 tokens, 14.706 tokens-per-sec
Peak memory: 7.382 GB

Numerical agreement with the reference implementation

Compared against the HF modeling_sensenova_loop.py on an 11-token probe: per-position logit cosine 0.9999+, argmax agreement 11/11, and repeated forwards are bit-identical.

Notes for reviewers

  • The cache is sized by the execution plan, not by the physical layer count. loop_settings expands [0..3] + [4..27] x2 + [28..31] = 56 visits, so make_cache() returns 56 slots. This is the same convention the existing iquestloopcoder model uses (2 * num_layers for a full-depth loop); SenseNova generalises "all layers twice" to "an interval N times", which is why len(plan) is used instead of a constant multiplier.
  • The mHC tensors must stay fp32. quant_predicate / cast_predicate keep the mHC weights and biases, the GDN A_log/dt_bias and every RMSNorm weight out of quantization and out of dtype casting. The 20-iteration Sinkhorn is numerically sensitive and bf16 there silently produces garbage.
  • Text tower only: the visual encoder, the MTP head and the loop gate are not implemented.
  • Pre-existing test failures: a full unittest discover tests/ run reports 23 failures on this machine (numerically sensitive batch / cache / ssm tests), and a clean checkout of main produces an identical failure set. test_all_models passes with the new config.

## Requirements

- ☑️ I understand it is strictly prohibited to use AI to write PR description
- AI usage disclosure: (fill in before marking ready for review)

## Model information

- Name: SenseNova-Loop-9B
- Homepage: https://huggingface.co/sensenova/SenseNova-Loop-9B
- Reference implementation: https://huggingface.co/sensenova/SenseNova-Loop-9B/blob/main/modeling_sensenova_loop.py
  (published by the model authors as remote code; not in transformers upstream)

## Supported checkpoints

- https://huggingface.co/sensenova/SenseNova-Loop-9B (BF16 reference)
- https://huggingface.co/listener8341/SenseNova-Loop-9B-MLX-6bit (MLX 6-bit, produced by this model file
  with `mlx_lm.convert`)

## Verification

Run mlx-lm command:

```console
mlx_lm.generate --model SenseNova-Loop-9B-6bit -p "The secret to baking a good cake is" -m 300
```

Output:

```
The secret to baking a good cake is a combination of several key factors:

**Precision & Measurement**
- Use a kitchen scale for accuracy. Baking is chemistry, and even small
  imprecisions can throw off the balance.
- Measure ingredients by weight rather than volume when possible.

**Room-Temperature Ingredients**
- Let butter, eggs, and milk come to room temperature. This helps with
  emulsification and even mixing.

**Fresh Leavening**
- Use fresh baking powder, baking soda, or yeast. Old leavening agents
  won't activate properly.

**Don't Overmix**
- Mix just until combined. Overmixing develops gluten, leading to a tough,
  dense crumb.

**Patience**
- Bake at the right temperature. Too hot can cause cracking or a gummy center.
- Test doneness with a toothpick rather than relying solely on time.

**Quality Ingredients**
- Use good butter

Prompt: 18 tokens, 57.528 tokens-per-sec
Generation: 300 tokens, 14.706 tokens-per-sec
Peak memory: 7.382 GB
```

## Numerical agreement with the reference implementation

Compared against the HF `modeling_sensenova_loop.py` on an 11-token probe: per-position logit
cosine 0.9999+, argmax agreement 11/11, and repeated forwards are bit-identical.

## Notes for reviewers

- **The cache is sized by the execution plan, not by the physical layer count.** `loop_settings`
  expands `[0..3] + [4..27] x2 + [28..31]` = 56 visits, so `make_cache()` returns 56 slots. This
  is the same convention the existing `iquestloopcoder` model uses (`2 * num_layers` for a
  full-depth loop); SenseNova generalises "all layers twice" to "an interval N times", which is
  why `len(plan)` is used instead of a constant multiplier.
- **The mHC tensors must stay fp32.** `quant_predicate` / `cast_predicate` keep the mHC weights
  and biases, the GDN `A_log`/`dt_bias` and every RMSNorm weight out of quantization and out of
  dtype casting. The 20-iteration Sinkhorn is numerically sensitive and bf16 there silently
  produces garbage.
- Text tower only: the visual encoder, the MTP head and the loop gate are not implemented.
- Pre-existing test failures: a full `unittest discover tests/` run reports 23 failures on this
  machine (numerically sensitive batch / cache / ssm tests), and a clean checkout of `main`
  produces an identical failure set. `test_all_models` passes with the new config.

This branch has not been deployed

No deployments
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