30 Commits

Author SHA1 Message Date
Vladimir Mandic 2ef1a0c87b stricter ty
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-09-08 10:22:42 +02:00
Ryan Meador 6013110e96 fix: honor offline mode in model loaders 2026-09-06 10:10:36 -04:00
CalamitousFelicitousness 6b92f2ba03 feat(model): add anima 2.9b as a base reference model
Anima-2.9B is a depth-expanded finetune of Anima 1.0 Base carrying 40
transformer blocks against the base repo's 28. The reference entry points at
the Diffusers conversion. Single-file releases load through the native loader:
TransformerSpec gains an infer_config hook, the Anima spec uses it to size
num_layers to the block indices in the file, and model_anima routes a
checkpoint-selected safetensors through the loader with the remaining
components from the base repo.
2026-09-05 01:45:49 +01:00
Dity0 cc91a05870 fix native transformer pre-quants 2026-08-11 10:59:29 +03:00
Dity0 712a13f1a0 Move SDNQ to upstream SDNQ repo 2026-08-10 12:13:10 +03:00
Disty0 75926e6fc4 Remove sdnq_use_quantized_matmul and use sdnq_quantize_matmul_mode instead 2026-07-15 18:45:30 +03:00
Disty0 32650c7e50 SDNQ add fused Triton kernels 2026-07-13 18:01:01 +03:00
CalamitousFelicitousness ce84b2d183 perf(model): adopt fp8 weights through the uint8 codec when fp8 cannot compile
Triton cannot compile e4m3 loads before sm_89, so fp8 weights fall back
to eager dequant there. The uint8-backed float8_e4m3fn_sdnq codec decodes
identically now that subnormals are handled (the two NaN codes become
+/-480), and its compiled dequant runs about 6x faster than eager native
fp8. Pre-quantized fp8 layers are viewed as uint8 at adoption when
compiled dequant is enabled on such hardware; the eager gate remains the
safety net for every other fp8 path.
2026-07-12 03:44:54 +01:00
CalamitousFelicitousness 0997526394 feat(model): load nvfp4 comfy_quant checkpoints via sdnq
nvfp4 layers keep their packed 4-bit codes and land on SDNQ grouped
quantization as float4_e2m1fn: the nibble order is swapped once at load,
the e4m3 block scales are unswizzled from the cuBLAS tile layout, and
the fp32 global scale folds into them as per-group scales. Marker
orig_shape acts as a cross-check and alignment padding is sliced
against the model dimensions.

- reject nvfp4 markers with unknown group sizes or convrot flags
- accept uint8 storage in the krea2 real-file check
2026-07-12 03:44:54 +01:00
CalamitousFelicitousness d005ac5aa1 feat(model): support comfy_quant header metadata containers
Newer quantized checkpoints record per-layer formats in the safetensors
header _quantization_metadata instead of marker tensors. The native loader
now reads the header map, re-keys it through the same prefix strip as the
tensors, and transcodes it into marker tensors so both container forms
share one detection path; header entries win over markers.

- drop optional input_scale sidecars for marked layers
- map full_precision_matrix_mult onto the sdnq per-layer matmul exclusion list
- log the detection source (markers, header, both)
2026-07-11 20:26:12 +01:00
CalamitousFelicitousness 5d5ede5c47 feat(model): load convrot comfy_quant checkpoints via sdnq hadamard
ConvRot is the regular Hadamard rotation SDNQ implements: identical
construction, normalization, axis, and dequant order. Per-layer markers
map onto the dequantizer's use_hadamard and hadamard_group_size; group
sizes must be powers of 4 and divide in_features, else base-repo
fallback. Detection carries per-layer metadata since files mix plain
and rotated layers.
2026-07-11 06:40:08 +01:00
CalamitousFelicitousness 8c884c1e02 feat(model): secondary unet override slot and ideogram4 native loading
One UNET override cannot serve dual-transformer arches: ideogram4
conditional/unconditional and wan combined-stage experts need separate
files, and previously a single override landed on both experts.

- sd_unet_secondary option with per-slot tracking, consumed-state sync,
  arch-change reset, and incompatible-override fallback
- dropdown renders beside the primary, follows it into quicksettings,
  and is visible only for dual-transformer model types
- ideogram4 native single-file spec with a quant-aware fused-qkv
  converter; such converters run before comfy_quant detection via
  TransformerSpec.converter_handles_quant
- quicksettings render in configured order (sort keyed on the option
  object and always fell back to alphabetical)
- post-load dtype warning skips quantized transformers
2026-07-11 06:40:07 +01:00
CalamitousFelicitousness 2a7d4b4037 feat(model): extend comfy_quant loading to float8_e4m3fn
Parameterize the pre-quantized comfy_quant path by format so fp8
tensorwise checkpoints load alongside int8; both map onto SDNQ's
symmetric dequant for the matching weights dtype. Containers are
mislabeled in the wild, so the stored weight dtype is validated
against the marker, mixed-format files are rejected, and markers
carrying a convrot rotation flag fall back to the base repo since
they may require runtime inverse rotation.
2026-07-10 02:27:24 +01:00
CalamitousFelicitousness 68c1ea8e78 feat(model): load comfyui comfy_quant int8 checkpoints via sdnq
Detect comfy_quant markers in native single-file transformer loads and
adopt the pre-quantized tensors as SDNQ int8 layers instead of rejecting
them. ComfyUI int8_tensorwise is a strict subset of SDNQ symmetric int8,
so weights and scales are taken bit-exact with no dequantize-requantize
round trip; quantized matmul and scale-dtype settings apply as usual.

- detect_comfy_quant/remap_comfy_quant helpers plus a prequantized
  builder in native_transformer; file markers dictate the layer set
- unsupported formats and wrong-arch markers fall back to the base repo
- offline unit tests and an opt-in real-file krea2 test
2026-07-10 01:54:27 +01:00
CalamitousFelicitousness 4c289e8c9d fix(model): load transformer from all-in-one checkpoints in native loader
All-in-one exports bundle the text encoder and VAE alongside the
transformer under LDM-style family prefixes (cond_stage_model.,
first_stage_model., text_encoders., vae.). The native loader treated
those keys as a mixed-prefix error and rejected the file. Drop known
companion families before prefix detection and log what was skipped;
keys matching neither a transformer prefix nor a known family still
raise. TE and VAE keep coming from the base repo or their own overrides.
2026-07-09 00:35:00 +01:00
CalamitousFelicitousness 0e6158438f refactor(loader): collapse native-load logging to one summary line
strip_prefix returns the detected prefix instead of logging it, so the load
summary reports it alongside the key count and the redundant reading-state
marker is gone. Four near-identical cls/file lines become one.
2026-07-05 18:21:28 +01:00
CalamitousFelicitousness f9d2bbe080 fix(krea2): zero-fill dormant last.up/last.down residual branch
Base ships last.up all-zeros so the branch is a no-op; pre-branch
finetunes omit both keys. A zero_init_missing spec field zero-fills
them on load instead of falling back to the base transformer.
2026-07-05 18:05:13 +01:00
Vladimir Mandic 0e35079f06 attempt to load incomplete model
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-06-29 13:39:46 +02:00
CalamitousFelicitousness 5f50117bf9 docs(native-loader): document shape-mismatch override behavior 2026-06-05 20:08:43 +01:00
CalamitousFelicitousness 32081ade7c refactor(native-loader): replace required_markers with reactive fallback
A converter error or load_state_dict mismatch now raises OverrideArchMismatch, which load_transformer catches to drop the override and load the base transformer. No per-arch markers to maintain.
2026-06-04 21:20:10 +01:00
CalamitousFelicitousness 596cae1b90 fix(native-loader): handle arch-mismatched UNET/DiT override on cold start 2026-06-03 03:23:24 +01:00
CalamitousFelicitousness 77913c7c0a docs: cleanup
- generic.load_transformer: shorter dispatch description, no internal taxonomy
- native_transformer.load: trim kwargs forwarding wording
- sd_unet revert: one-line comment
- test: shorten kwargs-forwarding docstrings
2026-05-31 02:04:56 +01:00
CalamitousFelicitousness 18656d1d79 fix(native_transformer): forward load kwargs to from_config
load_transformer threads **kwargs into its from_pretrained and from_single_file branches. The native dispatch branch bypasses both loaders and builds via cls.from_config, so those kwargs were dropped there. Thread them through load, build_component, and build_component_quantized into from_config so callers passing extra args alongside native_spec are honored instead of silently dropped. Siblings do not receive them.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness c29168a766 feat(native_transformer): implement per-tensor pre-mode SDNQ quantization
The transformer load path now mirrors diffusers' load_model_dict_into_meta: build the component inside init_empty_weights(include_buffers=False) so parameter slots stay meta while computed buffers keep their __init__ values, then iterate the converted state_dict tensor by tensor. Each tensor is dispatched through SDNQQuantizer.check_if_quantized_param and create_quantized_param so Linear/Conv/Embed weights are packed to uint4 in flight, while non-quantizable parameters go through accelerate.set_module_tensor_to_device.

Peak memory during transformer load drops from the full bf16 model size to one layer's worth of bf16 plus the running uint4 result. The prior load_state_dict + .to(dtype) + post-walk sdnq_quantize_model sequence remains as the fallback path for siblings and non-SDNQ quant types.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness 7ae45c59d4 refactor(native_transformer): accept precomputed quant_args from caller
generic.load_transformer already computes quant_args and quant_type at the top of the function, but native_transformer.load was redoing the same work and emitting a duplicate 'Quantization: module=Model ...' log line milliseconds later. Pass them through instead; fall back to computing them when called directly (model_anima still does so).
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness 75933bfaee feat(native_transformer): log per-phase progress to reduce load silence
The native loader was emitting one line at dispatch, a single line after prefix detection, and the total time at the end. For an 18 GB transformer that meant ~60s of silence with no indication anything was happening.

Add DEBUG lines before each long phase: read_state_dict, optional converter, load_state_dict into the model, and dtype cast. Total-time log at the end is unchanged.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness b29178743c fix(native_transformer): forward modules_to_not_convert to sdnq_quantize_model
apply_quant called sdnq_quantize_model(transformer, op="transformer")
without the per-call skip lists, dropping modules_to_not_convert and
modules_dtype_dict that the caller passed into generic.load_transformer.
The from_pretrained path receives them via quantization_config; the
native path now threads them directly into the explicit quantizer call.

Plumbed load -> build_component -> apply_quant as keyword args. No
behavior change for callers that did not set the skip lists.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness 98fba8ddc3 feat(pipelines): wire native_spec dispatch in generic.load_transformer
New native_spec=None kwarg. When set and the UNET dropdown points at a
.safetensors, dispatches to native_transformer.load (threading
allow_quant/dtype/modules_to_not_convert/modules_dtype_dict). Pipelines
without a spec stay on cls.from_single_file unchanged.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness cec6d0dce5 refactor(anima): port anima_transformer to native_transformer
217-line bespoke loader collapses to a 40-line ANIMA_SPEC in
pipelines/anima/__init__.py (Cosmos converter + llm_adapter sibling +
Cosmos 1.0 forbidden marker).

Drop the class-keyed REGISTRY: Anima and raw Cosmos share
CosmosTransformer3DModel but need different specs. Specs pass via
explicit native_spec= kwarg; make_default_spec(cls) covers the
auto-converter case.
2026-05-31 00:24:33 +01:00
CalamitousFelicitousness 08ad6196d0 feat(pipelines): add native_transformer for single-file DiT loading
Read .safetensors, strip prefix, partition siblings, run optional
converter, from_config + load_state_dict + validate, dtype/quant/offload.
Per-arch knobs via TransformerSpec(cls, subfolder, prefixes, converter,
siblings, acceptable_missing, forbidden_markers). SiblingSpec covers
bundled components like Anima's llm_adapter. 36 offline tests.
2026-05-31 00:24:33 +01:00