Skip to content

Studio: reject a training random_seed outside the numpy range up front - #15176

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
vineethsaivs:fix/training-random-seed-range
Oct 26, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
vineethsaivs:fix/training-random-seed-range

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

A Studio training request with random_seed outside [0, 2**32 - 1] (for example -1) passes validation, loads the model, and only then fails with ValueError: Seed must be between 0 and 2**32 - 1.

Cause: TrainingStartRequest.random_seed accepted any int, but it reaches transformers.set_seed, which numpy bounds. The diffusion training seed already has this bound.

Fix: ge = 0, le = 2**32 - 1 on the field, so the request gets a 400 up front. The OpenAI fine-tuning seed uses the same model, so it is bounded too.

Test: pytest studio/backend/tests/test_studio_train_validation.py fails before for -1 and 2**32, passes after (57 passed with the OpenAI fine-tuning and LoRA seed tests).

random_seed accepted any int, but it reaches transformers.set_seed, which
numpy limits to [0, 2**32 - 1]. A value like -1 passed validation, loaded
the model and only then failed in set_seed. Bound the field so the request
is rejected with a 400 before any model work starts.
danielhanchen added a commit that referenced this pull request Oct 25, 2026
…15182)

## Summary

`tests/utils/test_single_row_cached_attention.py` errors on all 64 cases
on main since #15171 (K/V straight into the cache slot, opt-in
CUDA-graph decode). That fails the `Core (HF=...)` legs on unrelated
PRs, for example #15176 and #15178:

```
AssertionError: Qwen3Attention_fast_forward_inference now reads ['_decode_attention_core', '_decode_graphs']; give the harness a CPU stand-in for each
```

The harness lifts `LlamaAttention_fast_forward_inference` and
`Qwen3Attention_fast_forward_inference` out of their files with `ast`,
and refuses to run if they read a global it does not provide. #15171
moved the cache and scratch buffer setup into
`unsloth/models/_decode_graphs.py` (`alloc_decode_buffers`,
`resize_decode_buffers`) and added the captured-step branch that calls
`_decode_attention_core`. The product is fine. The guard did what it is
meant to do and asked for stand-ins.

## Change

- `_decode_graphs`: the real module, loaded by file path. Its top level
is torch and the standard library only. `ENABLED` is forced to `False`,
because graph replay is CUDA-only. The test keeps running the real
`alloc_decode_buffers` / `resize_decode_buffers` instead of a copy.
- `_decode_attention_core`: a stand-in that raises if called. It is only
reached from a captured decode step, which this CPU harness never
enters, so reaching it would mean graph mode leaked in.

## Verification

- On main: `64 errors`. With this change: `64 passed`. It also passes
with `UNSLOTH_DECODE_CUDA_GRAPHS=1` set.
- Sabotage 1: writing the wrong V rows in
`_decode_graphs.alloc_decode_buffers` gives 56 failures. The real helper
is what the test exercises.
- Sabotage 2: skipping qwen3's 2D padding mask conversion in the decode
function gives 8 failures. The masking checks the file was written for
still bite.
@danielhanchen danielhanchen self-assigned this Oct 26, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T03:10:25.779220Z ca878fd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen merged commit 33114da into unslothai:main Oct 26, 2026
54 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.

2 participants