| """AGIWSNeuralQuant — Universal neural network quantization library.
|
|
|
| Unified architecture: one parameterized Quantizer for all formats,
|
| QuantizedWeight/QuantizedActivation containers, dual-path cross-quantization
|
| distillation, chunked dequant for minimal VRAM, QAT with learnable parameters
|
| via STE, SSM-aware exclusion patterns.
|
|
|
| Quantization primitives (pure tensor-level functions, no nn.Module wrappers):
|
| - ternary (BitNet 1.58): ternarize_tensor, ternary_dequantize, fake_ternarize
|
| - nf (QLoRA NormalFloat generalized): NF2/NF3/NF4/NF8 LUTs, quantize/dequantize, pack/unpack, double_quant
|
| - fp8 (E4M3/E5M2): FP8 LUTs, quantize/dequantize
|
| - fp4 (E2M1 / NVFP4 / MXFP4): FP4 LUT, quantize/dequantize, pack/unpack, E8M0
|
| - ste (Straight-Through Estimator): STEQuantize, fake_quantize
|
|
|
| Layer wrappers live ONLY in base.py (QuantizedModule) — no per-format
|
| nn.Module classes. The unified Quantizer (quantizer.py) + presets (presets.py)
|
| configure all 40+ formats as parameters, not separate classes.
|
| """
|
|
|
| __version__ = "0.6.5"
|
|
|
|
|
| from agiws_neural_quant.dispatch import quantize_model, count_quantizable_layers, make_quantizer, save_model, load_model
|
| from agiws_neural_quant.base import QuantizedModule, QuantizedWeight, QuantizedActivation
|
| from agiws_neural_quant.quantizer import Quantizer
|
| from agiws_neural_quant.presets import FORMAT_PRESETS, get_preset
|
|
|
|
|
| from agiws_neural_quant.ssm_patterns import (
|
| get_ssm_exclude_patterns,
|
| get_ssm_subtree_patterns,
|
| )
|
|
|
|
|
| from agiws_neural_quant.training_unified import (
|
| UnifiedQATWrapper,
|
| dual_path_loss,
|
| strip_latent,
|
| )
|
|
|
|
|
| from agiws_neural_quant.training import fake_quantize, STEQuantize
|
| from agiws_neural_quant.training.ste import STECodebook, fake_codebook_quantize
|
| from agiws_neural_quant.ternary import (
|
| ternarize_tensor,
|
| ternary_dequantize,
|
| fake_ternarize,
|
| )
|
| from agiws_neural_quant.nf import (
|
| make_normalfloat_lut,
|
| NF2_LUT,
|
| NF3_LUT,
|
| NF4_LUT,
|
| NF8_LUT,
|
| quantize_nf,
|
| dequantize_nf,
|
| pack_nf,
|
| unpack_nf,
|
| double_quantize_scales_2d,
|
| dequantize_scales_2d,
|
| )
|
| from agiws_neural_quant.fp8 import (
|
| FP8_E4M3_LUT,
|
| FP8_E5M2_LUT,
|
| quantize_fp8,
|
| dequantize_fp8,
|
| )
|
| from agiws_neural_quant.fp4 import (
|
| FP4_E2M1_LUT,
|
| quantize_fp4,
|
| dequantize_fp4,
|
| pack_fp4,
|
| unpack_fp4,
|
| E8M0_LUT,
|
| )
|
| from agiws_neural_quant.fp6 import (
|
| FP6_E3M2_LUT,
|
| FP6_E2M3_LUT,
|
| quantize_fp6,
|
| dequantize_fp6,
|
| pack_fp6,
|
| unpack_fp6,
|
| )
|
| from agiws_neural_quant import kquant
|
| from agiws_neural_quant.kquant import (
|
| quantize_blocks,
|
| dequantize_blocks,
|
| )
|
|
|
|
|
| from agiws_neural_quant.cache import (
|
| get_cache_dir,
|
| get_cache_path,
|
| is_cache_valid,
|
| get_sources_needing_cache,
|
| save_cache,
|
| load_cache,
|
| CaptureConfig,
|
| select_modules,
|
| capture_with_hooks,
|
| save_layer_cache,
|
| load_layer_cache,
|
| load_layer_io,
|
| list_cached_names,
|
| validate_cache_contents,
|
| clean_old_cache,
|
| TeacherCache,
|
| )
|
|
|
|
|
| from agiws_neural_quant.extract import (
|
| extract_subcheckpoint,
|
| extract_vision_encoder,
|
| extract_module_group,
|
| load_subcheckpoint,
|
| list_shards,
|
| find_keys,
|
| ExtractReport,
|
| )
|
|
|
|
|
| from agiws_neural_quant.converters import (
|
| convert_model,
|
| detect_format,
|
| list_safetensors_keys,
|
| read_safetensors_tensor,
|
| stream_safetensors,
|
| write_safetensors,
|
| detect_quant_layout,
|
| GGUFReader,
|
| load_gguf_modules,
|
| gguf_to_quantized_modules,
|
| convert_nvfp4_safetensors_tensor,
|
| dequantize_nvfp4_safetensors,
|
| )
|
|
|
|
|
| from agiws_neural_quant.kquant.gguf_packed import (
|
| dequant_gguf_slice,
|
| bytes_per_row as gguf_bytes_per_row,
|
| )
|
|
|
|
|
| from agiws_neural_quant.transformers_integration import (
|
| NeuralQuantConfig,
|
| NeuralQuantHfQuantizer,
|
| NEURAL_QUANT_METHOD,
|
| )
|
|
|
|
|
| from agiws_neural_quant.bnb.bnb_packed import (
|
| dequant_bnb_slice,
|
| dequant_bnb_nf4,
|
| dequant_bnb_int8,
|
| )
|
| from agiws_neural_quant.bnb.bnb_loader import load_bnb_model
|
|
|
|
|
| from agiws_neural_quant.analysis import LayerAnalyzer, SplitReport, LayerResult, AnomalyReport
|
|
|
|
|
| from agiws_neural_quant.trading_lr import TradingLR, DEMA, ATR, RSI
|
|
|
|
|
| from agiws_neural_quant.arch_replace import MambaLayer, ReplaceModule, jamba_replace
|
|
|
|
|
| from agiws_neural_quant.mtp import MTPHead, attach_mtp
|
|
|
| __all__ = [
|
|
|
| "quantize_model",
|
| "count_quantizable_layers",
|
| "make_quantizer",
|
| "save_model",
|
| "load_model",
|
| "QuantizedModule",
|
| "QuantizedWeight",
|
| "QuantizedActivation",
|
| "Quantizer",
|
| "FORMAT_PRESETS",
|
| "get_preset",
|
|
|
| "get_ssm_exclude_patterns",
|
| "get_ssm_subtree_patterns",
|
|
|
| "UnifiedQATWrapper",
|
| "dual_path_loss",
|
| "strip_latent",
|
|
|
| "fake_quantize",
|
| "STEQuantize",
|
| "STECodebook",
|
| "fake_codebook_quantize",
|
|
|
| "ternarize_tensor",
|
| "ternary_dequantize",
|
| "fake_ternarize",
|
|
|
| "make_normalfloat_lut",
|
| "NF2_LUT",
|
| "NF3_LUT",
|
| "NF4_LUT",
|
| "NF8_LUT",
|
| "quantize_nf",
|
| "dequantize_nf",
|
| "pack_nf",
|
| "unpack_nf",
|
| "double_quantize_scales_2d",
|
| "dequantize_scales_2d",
|
|
|
| "FP8_E4M3_LUT",
|
| "FP8_E5M2_LUT",
|
| "quantize_fp8",
|
| "dequantize_fp8",
|
|
|
| "FP4_E2M1_LUT",
|
| "quantize_fp4",
|
| "dequantize_fp4",
|
| "pack_fp4",
|
| "unpack_fp4",
|
| "E8M0_LUT",
|
|
|
| "FP6_E3M2_LUT",
|
| "FP6_E2M3_LUT",
|
| "quantize_fp6",
|
| "dequantize_fp6",
|
| "pack_fp6",
|
| "unpack_fp6",
|
|
|
| "kquant",
|
| "quantize_blocks",
|
| "dequantize_blocks",
|
|
|
| "get_cache_dir",
|
| "get_cache_path",
|
| "is_cache_valid",
|
| "get_sources_needing_cache",
|
| "save_cache",
|
| "load_cache",
|
| "CaptureConfig",
|
| "select_modules",
|
| "capture_with_hooks",
|
| "save_layer_cache",
|
| "load_layer_cache",
|
| "load_layer_io",
|
| "list_cached_names",
|
| "validate_cache_contents",
|
| "clean_old_cache",
|
| "TeacherCache",
|
|
|
| "extract_subcheckpoint",
|
| "extract_vision_encoder",
|
| "extract_module_group",
|
| "load_subcheckpoint",
|
| "list_shards",
|
| "find_keys",
|
| "ExtractReport",
|
|
|
| "convert_model",
|
| "detect_format",
|
| "list_safetensors_keys",
|
| "read_safetensors_tensor",
|
| "stream_safetensors",
|
| "write_safetensors",
|
| "detect_quant_layout",
|
| "GGUFReader",
|
| "load_gguf_modules",
|
| "gguf_to_quantized_modules",
|
| "convert_nvfp4_safetensors_tensor",
|
| "dequantize_nvfp4_safetensors",
|
|
|
| "dequant_gguf_slice",
|
| "gguf_bytes_per_row",
|
|
|
| "NeuralQuantConfig",
|
| "NeuralQuantHfQuantizer",
|
|
|
| "dequant_bnb_slice",
|
| "dequant_bnb_nf4",
|
| "dequant_bnb_int8",
|
| "load_bnb_model",
|
|
|
| "LayerAnalyzer",
|
| "SplitReport",
|
| "LayerResult",
|
| "AnomalyReport",
|
|
|
| "TradingLR",
|
| "DEMA",
|
| "ATR",
|
| "RSI",
|
|
|
| "MambaLayer",
|
| "ReplaceModule",
|
| "jamba_replace",
|
|
|
| "MTPHead",
|
| "attach_mtp",
|
| ] |