Repository navigation
Gemma 3 - #1986
Merged
Merged
Gemma 3#1986
Conversation
abiswas-realadvice
pushed a commit
to abiswas-realadvice/unsloth
that referenced
this pull request
May 14, 2026
* Update llama.py * GRPO optimized * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Selective Log softmax * Fix GRPO bsz * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Fix TRL * Metrics GRPO * Update rl_replacements.py * Update rl_replacements.py * No compile * Update rl.py * Remove docs * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * llama-quantize on WINDOWS WSL error fix - edit save.py (gguf saving breaks) (unslothai#1649) * edit save.py to fix gguf saving breaks. * add check for .exe or not exe file extension for linux and windows * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update llama.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update llama.py * Update llama.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * unsloth_num_chunks * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py (unslothai#1754) Fix typo in comment: know -> now. This was printed when running the Llama3.1_(8B)-GRPO.ipynb example notebook, so I'd expect others to run into it as well. * Optional logits * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * fix an import error (unslothai#1767) * fix an import error * Delete .gitignore * Update loader.py * Update save.py --------- Co-authored-by: Daniel Han <[email protected]> * SamplingParams * Convert mask to float (unslothai#1762) * [Windows Support] Add latest `xformers` wheels to pyproject.toml (unslothai#1753) * Add latest xformers * Add a couple of lines to docs * vLLMSamplingParams * Update __init__.py * default num_chunks == -1 * Versioning * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update _utils.py * Update rl_replacements.py * Update rl_replacements.py * Update pyproject.toml * Update pyproject.toml * Export Model to ollama.com (unslothai#1648) * Ollama Export Model to ollama.com Signed-off-by: Jyotin Goel <[email protected]> * Check for model_name Signed-off-by: Jyotin Goel <[email protected]> * subprocess use instead of requests | added check for ollama server Signed-off-by: Jyotin Goel <[email protected]> * create_ollama_model Signed-off-by: Jyotin Goel <[email protected]> * create_ollama_model | fix Signed-off-by: Jyotin Goel <[email protected]> * Push to Ollama Signed-off-by: Jyotin Goel <[email protected]> --------- Signed-off-by: Jyotin Goel <[email protected]> * Update cross_entropy_loss.py * torch_cuda_device * Update utils.py * Update utils.py * Update utils.py * device * device * Update loader.py * Update llama.py * Update README.md * Update llama.py * Update llama.py * Update _utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * __version__ * Update rl.py * Bug fixes * Bug fixes * Update llama.py * Update _utils.py * _wrap_fast_inference * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update _utils.py * SFT dataset prepare * Update pyproject.toml * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl.py * Update llama.py * Update llama.py * Update utils.py * bug fix * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update llama.py * Update __init__.py * Update _utils.py * Update _utils.py * Update _utils.py * Update _utils.py * Update _utils.py * Update rl.py * Update rl.py * Update rl.py * Update _utils.py * Update __init__.py * Update _utils.py * Version * versioning * Update _utils.py * Update llama.py * Update llama.py * Bug fixes * FastModel * __doc__ * Update vision.py * Update loader.py * Update loader.py * Update loader.py * version * move use_modelscope to _utils (unslothai#1938) * move use_modelscope to _utils * Update _utils.py * Update loader.py --------- Co-authored-by: Daniel Han <[email protected]> * Don't use revision when loading model_config and is_peft=True (unslothai#1949) * More syntax warnings (unslothai#1944) * move use_modelscope to _utils * fix * Update _utils.py * Update loader.py --------- Co-authored-by: Daniel Han <[email protected]> * Update loader.py * Full finetuning and other fixes * UNSLOTH_ENABLE_FULL_FINETUNING * Update loader.py * Update loader.py * Update loader.py * Update vision.py * Update vision.py * full finetuning * Update loader.py * Update loader.py * Update loader.py * Update _utils.py * max_seq_length * Update rl.py * Update rl.py * Update rl.py * Update pyproject.toml * AutoModelForImageTextToText * Update mapper.py * Update pyproject.toml * Update _utils.py * Update _utils.py * Update _utils.py * Batch samples * Update loader.py * Update loader.py * Update loader.py * Update loader.py * Update _utils.py * Update loader.py * Update vision.py * Update loader.py * Update vision.py * Update vision.py * Update vision.py * Update mapper.py --------- Signed-off-by: Jyotin Goel <[email protected]> Co-authored-by: Gennadii Manzhos <[email protected]> Co-authored-by: Seth Weidman <[email protected]> Co-authored-by: Nino Risteski <[email protected]> Co-authored-by: Edd <[email protected]> Co-authored-by: Ben <[email protected]> Co-authored-by: Jyotin Goel <[email protected]> Co-authored-by: Kareem <[email protected]> Co-authored-by: Wilson Wu <[email protected]>
danielhanchen
added a commit
that referenced
this pull request
Nov 22, 2026
…sh-attn instead of --diffusion-fa) (#18787) Studio's sd.cpp speed and offload flags send `--diffusion-fa` (`native_speed_flags` and `offload_flags` in `sd_cpp_args.py`). The pinned build, `master-982-0518b34-u27b9ddc`, now treats that flag as a deprecated alias: ``` --diffusion-fa deprecated; use --flash-attn off,diffusion=on ``` So the flag Studio adds for speed turns text-encoder flash attention off. Without it, the binary's own `auto` would turn it on for CPU, CUDA MMA and Metal. An LLM text encoder (Qwen3, Qwen3-VL, Mistral) then builds the full `[heads, n, n]` F32 score matrix for every layer. On CPU that costs time. On Vulkan, once the matrix passes the 4 GiB storage-buffer limit, the op falls back to the CPU. That is leejet/stable-diffusion.cpp #1986: Qwen3-VL-32B at about 4.2k tokens on an RX 7900 XTX, fixed upstream by #1987, which only helps when flash attention is actually on for the text encoder. ## Change - On builds whose `--help` documents per-module `--flash-attn` assignments (`te=on|off`), the managed flags now carry `--flash-attn off,diffusion=on,te=auto` in place of `--diffusion-fa`. - The diffusion model keeps flash attention forced on, as before. The text encoder goes back to the binary's own per-backend auto: on for CPU, CUDA and HIP with MMA, Metal and Vulkan on NVIDIA RTX, and decided by its timed probe elsewhere, so no backend runs a text-encoder kernel its own probe rejected. The VAE keeps it off, as `--diffusion-fa` had it, so VAE output is unchanged. - The rewrite runs at command assembly in the sd-cli image, sd-cli video and sd-server builders, and on the speed flags in `SdCppEngine.generate`. One `--flash-attn` is emitted even when both the offload and speed lists asked for `--diffusion-fa`. - The memory planners and tests that read the offload lists still see `--diffusion-fa`. - A user's own extra args come last and win, as before (sd.cpp's parser is last-wins). - Older builds without the module syntax, or a binary whose help cannot be read, keep `--diffusion-fa`. The help probe is cached per binary path, size and mtime, the same way as the existing `--conv-direct` probe. ## Tests New `tests/test_sd_cpp_flash_attn_modules.py` (CPU), using the pinned build's own help text. It covers: - the server, sd-cli image and sd-cli video commands - offload plus speed producing a single `--flash-attn` - the engine path with a user override - builds without the module syntax - unknown binaries `test_differential.py`: DISCRIMINATING. 4 tests fail on main and pass here, 1 is new API, 1 is unchanged, head_fail=0. The sd.cpp and H3 native suites pass: 2123 passed, 6 skipped. Detection was checked against the real pinned Linux `sd-cli` binary. ## Results The timings below were taken with `te=on`. On the CPU backend the binary's auto resolves to on, so `te=auto` runs the same kernel there. The CPU of a Colab L4 VM: Xeon @ 2.20 GHz (Cascade Lake), 6 cores. The pinned release's Linux CPU `sd-cli` was used for both arms. Z-Image Turbo Q4_K_M with the Qwen3-4B Q8_0 encoder, 512 px, 1 step, seed 42. The only difference between the arms is the flag. Arms were interleaved over 2 rounds, and both rounds of each arm matched to within 0.3 s. | Prompt | Encode, `--diffusion-fa` | Encode, `--flash-attn off,diffusion=on,te=on` | Total | |---|---|---|---| | ~900 tokens | 14.74 / 14.45 s | 9.99 / 10.25 s (1.45x) | 74.2 -> 69.3 s | | ~3000 tokens | 78.39 / 78.60 s | 37.31 / 37.11 s (2.11x) | 189.8 -> 148.7 s (1.28x) | - Peak RSS was the same: 8.6 to 8.7 GB, dominated by the weights. - Each flag's repeat render was pixel-identical. - Renders with the two flags differ only by flash-attention rounding in the encoder: PSNR 32.2 dB at ~900 tokens and 36.5 dB at ~3000 tokens, visually the same image. ARM CPUs (GitHub runners, relative timing; source builds of the same pin; FLUX.2 klein 4B Q4_0 + Qwen3-4B Q4_0, 256 px, 1 step; medians of 3 rotated rounds). Text-encode seconds: | Runner | `--diffusion-fa` | module flag | |---|---|---| | ubuntu-24.04-arm (Neoverse N2, 4 cores) | 7.86 | 5.85 (1.34x) | | windows-11-arm | 37.35 | 35.66 (1.05x) | | macos-15 (M1 virtual, 3 vCPU) | 17.62 | 16.70 (a tie: run-to-run spread +-3-4 s) | ## Not proven here - Vulkan was not measured: the Colab L4 container has no working NVIDIA Vulkan ICD (`vkCreateInstance: ERROR_INCOMPATIBLE_DRIVER`). The 4 GiB fallback is upstream's report, not measured here. - Metal was not timed. The macOS runners' paravirtual GPU has no Metal flash attention and Studio places the graph on the CPU there. On real Apple GPUs the binary's own `auto` already picks flash attention for the encoder, which this restores. - No LPIPS against a non-FA reference. The encoder change is FA rounding only.
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.
No description provided.