unsloth/tests
danielhanchen 1b5ff90e49 flex: add gpt-oss inference support (bf16 + LoRA)
FlexGptOssInference mirrors FlexMoEInference with three arch-specific
pieces:

1. Attention sinks via flex_attention(return_lse=True) + post-softmax
   sigmoid(lse - sinks[h]) scaling. Same math as
   unsloth_zoo.flex_attention.attention_sink.
2. Per-layer sliding window: the walker passes both a full and a
   sliding-128 BlockMask; each attention forward picks one based on
   self.sliding_window.
3. gpt-oss rotary: first/second-half split with head_dim/2-sized
   cos/sin, not the Llama-style rotate_half on full-dim.

Reuses:
- refresh_moe_lora_merge_from_pristine for stacked-expert LoRA merge
  (transposed orientation branch covers gpt-oss's (E, H, 2I) layout)
- forward_native_grouped_mm — the GptOssExperts branch already handles
  the interleaved gate/up split + gate * sigmoid(gate * 1.702) activation

bnb-4bit: GptOssExpertsBnb4bit uses an nn.ModuleList per-expert loop
that can't be CUDA-graph-captured. __init__ detects it and disables
capture; decode still benefits from paged KV + flex_attention.

Also fixes a pre-existing deepcopy recursion in _LazyFlexEngineSentinel
that surfaced when the flex inference deepcopy ran on a model still
holding the sentinel (vision.py path doesn't pre-seed the inference
copy).

Bench on B200 (unsloth/gpt-oss-20b-BF16, max_new_tokens=64, chat):

| bs | HF naive | flex walker |
|---:|---------:|------------:|
|  8 |    258.9 |       832.1 |
| 32 |        — |      1595.3 |
| 48 |        — |      2146.4 |

3.2x over HF naive at bs=8. Parity: 24/24 greedy-token match vs HF on
3 chat prompts; cudagraph capture replay bitwise-matches eager decode.
2026-04-23 05:37:01 +00:00
..
python Add configurable PyTorch mirror via UNSLOTH_PYTORCH_MIRROR env var (#5024) 2026-04-15 11:39:11 +04:00
qlora Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks" 2025-12-01 07:24:58 -08:00
saving Add regression test for shell injection fix in GGML conversion (#4773) 2026-04-02 00:10:47 -07:00
sh Add configurable PyTorch mirror via UNSLOTH_PYTORCH_MIRROR env var (#5024) 2026-04-15 11:39:11 +04:00
studio/install Add ROCm test suite for PR #4720 (#4824) 2026-04-11 04:44:13 -07:00
utils feat: Add cactus QAT scheme support (#4679) 2026-04-15 07:40:03 -07:00
__init__.py Qwen 3, Bug Fixes (#2445) 2025-04-30 22:38:39 -07:00
flex_fastlm_bench.py inference: add AGPLv3 license headers 2026-04-21 13:19:01 +00:00
flex_fastlm_smoke.py inference: add AGPLv3 license headers 2026-04-21 13:19:01 +00:00
flex_gpt_oss_parity.py flex: add gpt-oss inference support (bf16 + LoRA) 2026-04-23 05:37:01 +00:00
flex_lazy_batch_smoke.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-04-21 14:58:27 +00:00
flex_lazy_live_smoke.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-04-21 14:58:27 +00:00
flex_moe_bench.py tests: add --chat_template to vLLM + HF benches; switch vLLM to llm.chat 2026-04-23 04:53:33 +00:00
flex_moe_merge_parity.py tests: flex_moe_merge_parity.py — numerical + perf check for MoE LoRA merge 2026-04-23 04:23:09 +00:00
flex_moe_micro_bench.py tests/flex_moe_micro_bench: coord_descent compile_opts profile 2026-04-22 18:31:15 +00:00
flex_moe_parity.py flex/moe: compile_walker option — 2x decode throughput on Qwen3 MoE 2026-04-22 17:27:41 +00:00
flex_moe_smoke.py flex: fix Qwen3 MoE smoke regressions (dtype / MoE MLP / peft patching) 2026-04-22 10:46:44 +00:00
flex_moe_vllm_bench.py tests: add --chat_template to vLLM + HF benches; switch vLLM to llm.chat 2026-04-23 04:53:33 +00:00
flex_sleep_mode_smoke.py [pre-commit.ci] auto fixes from pre-commit.com hooks 2026-04-21 14:58:27 +00:00
run_all.sh fix: add tokenizers to no-torch deps and TORCH_CONSTRAINT for arm64 macOS py313+ (#4748) 2026-04-01 06:12:17 -07:00
test_cli_export_unpacking.py studio: stream export worker output into the export dialog (#4897) 2026-04-14 08:55:43 -07:00
test_get_model_name.py feat: Add support for OLMo-3 model (#4678) 2026-04-15 07:39:11 -07:00
test_loader_glob_skip.py Add unit tests for HfFileSystem glob skip guard (#4854) 2026-04-06 08:54:36 -07:00
test_model_registry.py Revert "[FIX] Vllm guided decoding params (#3662)" 2025-12-01 05:43:45 -08:00
test_raw_text.py fix: check find() return value before adding offset in try_fix_tokenizer (#4923) 2026-04-09 06:15:46 -07:00