Skip to content

New quant types, activation quantization - #1034

Merged
dxqb merged 101 commits into
Nerogar:mergefrom
dxqb:compile_int8_svd
Nov 27, 2025
Merged

dxqb merged 101 commits into
Nerogar:mergefrom
dxqb:compile_int8_svd

Conversation

@dxqb

@dxqb dxqb commented Oct 4, 2025 •

Copy link
Copy Markdown
Collaborator

tldr: train LoRA twice as fast as before

image image

Switch to this PR:

git fetch origin pull/1034/head:pr-1034
git switch pr-1034

and then update.sh / update.bat


Compiled blocks

W8A8 quant types

  • Instead of only quantizing model weights, these new quant types also quantize activations
  • Performance improvement by 8bit matrix multiplications
  • Loss of precision in theory, but no noticable quality difference between Float8 W8A8 and the current Float8 type
  • Int8 might have a slight quality loss compared to fp8, but is also faster
  • Uses Triton for additional performance - untested on Windows
  • Performance might be different depending on NVIDIA architecture. Is fp8 faster than int8 on Blackwell? Untested

SVDQuant

Why no int4 / fp4?
Nunchaku (https://github.com/nunchaku-tech/nunchaku) have shown that 4-bit quants are possible at no noticable quality loss. Even though their matrix math is faster than 8-bit quants, my benchmarks show that there is no performance gain overall for training just by employing 4-bit matrix math. The 8-bit linear math is already fast enough - most of the remaining time in a training step is spent on bf16 attention and other layers.
I believe the additional improved performance achieved by Nunchaku is due to their manual kernel fusion, not due to 4bit matmuls - but happy to be proven wrong.

includes #1091

Comment thread modules/module/quantized/LinearW8A8.py Resolved
Comment thread modules/module/quantized/LinearW8A8.py Resolved
@dxqb

dxqb commented Oct 5, 2025 •

Copy link
Copy Markdown
Collaborator Author

Known issues:

  • Misaligned adress like [Bug]: Offloading with NF4 weights #827. Changing offloading alignment to 16 seemed to fix it again
  • Combining SVDQuant with offloading leads to NaN after a while (on Flux)
  • creating quantization cache directory fails if cache directory doesn't exist yet
  • resulting LoRAs files currently don't work externally if torch.compile is enabled, because it changes LoRA keys
  • resulting full finetunes can not be loaded externally, issues with LoRA loading for the same reason
  • numerical bug in float W8A8
  • test all models because checkpointing code has changed

@dxqb

dxqb commented Oct 13, 2025

Copy link
Copy Markdown
Collaborator Author
  • all checkpointing issues should be fixed now (lora loading, lora saving, full finetune saving)
  • float A8W8 bug fixed
  • SVD offloading should work now
  • various

@dxqb

dxqb commented Oct 14, 2025 •

Copy link
Copy Markdown
Collaborator Author

torch.compile bug workaround for Chroma and Qwen pushed, but

  • check other models
  • try torch.compile with dynamic=True, which might alltogether avoid this bug. How much slower is it?

@dxqb dxqb linked an issue Oct 15, 2025 that may be closed by this pull request
@dxqb dxqb added the merging last steps before merge label Nov 27, 2025
@dxqb dxqb mentioned this pull request Nov 27, 2025
@dxqb
dxqb changed the base branch from master to merge November 27, 2025 20:43
@dxqb
dxqb merged commit 7c255ac into Nerogar:merge Nov 27, 2025
dxqb added a commit that referenced this pull request Nov 28, 2025
@dxqb
dxqb deleted the compile_int8_svd branch November 28, 2025 21:12
Anai-Guo added a commit to Anai-Guo/OneTrainer that referenced this pull request Aug 31, 2026
__load_ckpt gained a required quantization parameter in Nerogar#1034, but the
call sites in the SD and SDXL loaders were never updated, so every .ckpt
load raises TypeError and is reported as 'could not load model'.
states-spec pushed a commit to states-spec/OneTrainer-Plus that referenced this pull request Oct 4, 2026
__load_ckpt takes a quantization argument since the quantization rework
(upstream Nerogar#1034, 2025-11), but load() still called it without one. The
TypeError was caught like any other load failure, so an SD 1.5/2.x model
in .ckpt format always ended in "could not load model". SDXL reads .ckpt
through from_single_file in its safetensors path first, so its fallback
was rarely reached, but the call was just as wrong. Upstream has the
same calls.

Checked through the real loaders with diffusers' ckpt converter stubbed
to return a tiny diffusers model (the stub refuses a pickled .ckpt as
safetensors, as diffusers does): SD 1.5 failed with "__load_ckpt()
missing 1 required positional argument: 'quantization'" before and
loads after; SDXL loads in both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011z4fFGwikUdiKShtgwZP9C
states-spec pushed a commit to states-spec/OneTrainer-Plus that referenced this pull request Oct 26, 2026
…preview-2)

compress sat between dtype and *args, so a positional call
LinearW8A8(dtype, in, out) bound in_features to compress. The fork's
rocm_check "W8A8 linear layers" check builds its layers that way and
failed with "Linear.__init__() missing 1 required positional argument:
'out_features'" since the compression change (Nerogar#1630). The quantizer
passes compress by keyword and is unaffected.

Upstream also adds a FIXME: bnb's Linear8bitLt takes
input_features/output_features, but __create_linear_layer passes
in_features/out_features, so the INT_8 weight dtype fails to construct
(TypeError). Checked: broken in the fork and upstream since Nerogar#1034. Not
fixed here, because more of that path has not run since then (e.g.
get_unquantized_weight has no Linear8bitLt case, so DoRA would read raw
int8 data).

Tested on the CPU: LinearW8A8(torch.int8, 64, 32, bias=True) builds 64
-> 32 with compress off (TypeError before); INT_W8A8 and FLOAT_8
quantized layers still build through replace_linear_with_quantized_layers.

(cherry picked from commit c2f3bff)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011z4fFGwikUdiKShtgwZP9C
states-spec pushed a commit to states-spec/OneTrainer-Plus that referenced this pull request Oct 26, 2026
- config version 13 and how the fork's migration numbers line up with
  upstream's; run_name/final_output_dir replace output_model_destination
- offloading: boundary checkpoint layers (non-reentrant), the
  model.offload_conductor dict, activation offloading through
  saved_tensors_hooks, disk streaming (default on), simplex, MemPools
  and OT_ROCM_MEM_POOLS
- adv_optm 2.5.16 (AdaMuon factored, AdaMuon Nesterov default, Prodigy
  Nesterov still broken), A8 dtypes and the Triton autotune/LDS note,
  INT_8 broken since Nerogar#1034, HF repo access check offline behavior
- OFT: DoRA-OFT and spectral norm clipping, the marker suffix rule for
  new adapter buffers, oft_scaled default history
- fragmentation diagnostics, the Qt theme toggle and last tab
- line references refreshed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011z4fFGwikUdiKShtgwZP9C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Effort: High merging last steps before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Offloading with NF4 weights

3 participants