Add support for MiniMax H3 T2V and I2V training
This commit is contained in:
1 parent
73cab2acf5
commit
8502a845b1
28 files changed
+4095
-41
No files matched your search
@@ -51,6 +51,13 @@ class OstrisQuantizer:
|
||||
"""Reconstruct the full weight in the original basis, in float32."""
|
||||
raise NotImplementedError
|
||||
|
||||
def dequantize_folded(self, module: "OstrisLinear") -> torch.Tensor:
|
||||
"""The full weight with any ACTIVATION-side transform folded in, i.e. a
|
||||
weight that computes the same output on raw activations. Used when
|
||||
re-quantizing into a different backend (which won't know about this
|
||||
backend's activation transforms). Default: same as dequantize."""
|
||||
return self.dequantize(module)
|
||||
|
||||
def requantize_(self, module: "OstrisLinear", fp_weight: torch.Tensor) -> None:
|
||||
"""Re-quantize in place from a full precision weight in the original basis
|
||||
(used by the continuous merge/reset method)."""
|
||||
@@ -179,6 +186,7 @@ def get_ostris_quantizer(qtype: str) -> Optional[OstrisQuantizer]:
|
||||
"""Resolve a qtype string to a quantizer backend instance, or None if the qtype
|
||||
does not belong to a custom backend. Add new backends here."""
|
||||
from toolkit.util.convrot_quant import CONVROT_QTYPES, get_convrot_quantizer
|
||||
from toolkit.util.nvfp4_quant import NVFP4_QTYPES, Nvfp4Quantizer
|
||||
from toolkit.util.orbit_quant import ORBIT_QTYPES, OrbitQuantizer
|
||||
from toolkit.util.orbit_vq_quant import ORBIT_VQ_QTYPES, OrbitVQQuantizer
|
||||
from toolkit.util.uintx_quant import UINTX_QTYPES, UIntXQuantizer
|
||||
@@ -190,6 +198,8 @@ def get_ostris_quantizer(qtype: str) -> Optional[OstrisQuantizer]:
|
||||
quantizer = OrbitVQQuantizer(**ORBIT_VQ_QTYPES[qtype])
|
||||
elif qtype in CONVROT_QTYPES:
|
||||
quantizer = get_convrot_quantizer(qtype)
|
||||
elif qtype in NVFP4_QTYPES:
|
||||
quantizer = Nvfp4Quantizer()
|
||||
elif qtype in UINTX_QTYPES:
|
||||
quantizer = UIntXQuantizer(UINTX_QTYPES[qtype])
|
||||
if quantizer is not None:
|
||||
@@ -324,8 +334,33 @@ def convert_linear_to_ostris(
|
||||
module: torch.nn.Linear, quantizer: OstrisQuantizer
|
||||
) -> bool:
|
||||
"""Quantize an nn.Linear in place (class swap). Returns True if the module was
|
||||
converted (or already was), False if it is not a candidate."""
|
||||
converted (or already was), False if it is not a candidate.
|
||||
|
||||
A module that is ALREADY quantized (e.g. loaded from a pre-quantized
|
||||
checkpoint) is re-quantized into the requested backend when the qtypes
|
||||
differ: the weight is dequantized and re-quantized layer by layer, so the
|
||||
full-precision transient never exceeds one layer's weight. Same qtype is
|
||||
a no-op (the shipped quantization is kept)."""
|
||||
if isinstance(module, OstrisLinear):
|
||||
current_qtype = getattr(module.ostris_quantizer, "qtype", None)
|
||||
if quantizer.qtype is None or current_qtype == quantizer.qtype:
|
||||
return True
|
||||
if not quantizer.can_quantize(module):
|
||||
return True # keep the existing quantization rather than dropping it
|
||||
# fold any activation-side transform (e.g. an AWQ pre_quant_scale) into
|
||||
# the weight so the new backend computes the same function on raw inputs
|
||||
weight = module.ostris_quantizer.dequantize_folded(module).to(
|
||||
module.ostris_orig_dtype
|
||||
)
|
||||
# backend state lives exclusively in buffers; leftover scalar attrs from
|
||||
# the old backend are inert
|
||||
module._buffers.clear()
|
||||
if quantizer.wants_fp32_weight:
|
||||
quantizer.quantize_(module, weight.to(torch.float32))
|
||||
else:
|
||||
quantizer.quantize_(module, weight)
|
||||
del weight
|
||||
module.ostris_quantizer = quantizer
|
||||
return True
|
||||
weight = getattr(module, "weight", None)
|
||||
if not isinstance(weight, torch.nn.Parameter) or not weight.dtype.is_floating_point:
|
||||
|
||||
Reference in new issue
Block a user