quantize: add option to automatically choose optimal quant types to reach a file/bpw target size at lowest error (#15550)
* Refactor pareto optimise and convexify
* Refactor lagrange_penalty()
* Refactor quantisation checks into its own function
* Exit loop if no better solution found
* Replace slope with cross product
* Adjust for small vector size
* Simplify candidates sorting
* Add comments to explain magic numbers
* Increase scale multiplier
* Move is_iq() into a lambda and remove unused variables
* Combine quant types
* Reduce bpw range
* Refactor outlier trimming
* Tighten worker allocator
* Check for direction reversal
* Simplify dequantisation
* Calculate bpw over all tensors
* Compute rows based on tensor shape and slice count
* Prioritise important tensors
* Select quantization type if target_bpw is set unless user specifies type and threads
* Relax lambda clamping
* Add signal handler
* Add save_bpw_state()
* Add load_bpw_state()
* Add delete_bpw_state()
* Persist progress
* Uninstall signal handler and cleanup
* Fix trimming logic
* Generate model ID hash
* Remove bias mode computation
* Remove --no-bias option
* Automatically determine if bias error is significant
* Reduce compute time by parallelising tensor processing - courtesy of https://github.com/ddh0
* Add quant types
* Add --keep-bpw-state option
* Refactor signal handlers
* Update quant types
* Minor refactoring
* Add tensor type and depth heuristics
* Add option to override bpw state file name
* Minor refactoring
* Finetune heuristics
* Update usage
* Fix lambda capture
* Update epsilon specifier
* Finetune heuristics
* Simplify tensor selection
* Read statistics from imatrix
* Add Euclidean-Cosine score to identify important tensors
* Improved is_important() logic
* Fix lambda capture bug in Windows and initialise candidate_types struct
* Remove processing statistics_data
* Add --disable-tensor-importance option
* Use more descriptive option naming
* Relax target bpw range
* Increase importance boost for final pass
* Add B/F16 to get_ftype()
* Process bpw targets up to B/F16
* Improve state checkpoint filename
* Add code comments
* Update usage()
* Update README.md
* Change checkpoint file magic
* Prepare for future optimization algorithms
* Add parse_target_size()
* Add --target-size option
* Implement target_size logic
* Update usage()
* Refactor parameter names
* Refactor option names
* Update parameter names
* Improve file handling
* Remove file deletion
* Refactor variable names
* Update usage()
* Add use_wce option
* Read statistics_data from imatrix
* Add experimental entropy-modulated weighted cosine error (WCE)
* Performance optimisations (AI assisted)
* Memory optimisations (AI assisted)
* Update output log
* Fix state file name generation and simplify_pareto() lambda capture
* Change tensor importance score logic
* Refactor is_quantizable()
* Improve WCE to be magnitude-aware
* Expected Output Error MSE
* Fix scale factor overwrite bug
* Test removing unused headers
* Remove wce flag
* Angle-aware/Magnitude-aware (MSE/WCE) hybrid error estimation
* Revert to weighted cosine error estimation
* Enhanced scaling factor
* Use centered‑normalized importance scaling factor (CNIF)
* Remove redundant logs
* Improve state file handling
* Update usage instructions
* Update ftype parsing logic
* Flag experimental features subject to future removal
* Fix --target-size description
* Fix "casts away qualifiers" compiler warning
* Exclude user defined tensors (--tensor-type) from the Lagrangian optimization
(courtesy of https://github.com/AesSedai)
* TurboQuant bias factor for inner-product sensitive tensors
* TurboQuant outlier mitigation
* Refactor TurboQuant improvements
* Fix remap tensor bug
* Remove --importance-pct option
* Refactor llama_model_quantize_params to expose a pure C interface
* Consolidate load/save process and remove --save-state flag
* Minor log output changes
* Use the tensor statistics' schema
* Add quant types
* Release finished tensors mmap allocation
* Reuse sample buffers
* Fix C2327 error when target compilation is a MS platform
* Minor refactoring and AI assisted optimizations
* Add uv.lock
* Minor refactoring and AI assisted optimizations
* Add Halko, Martinsson & Tropp randomized SVD condition number estimator
* Add kappa squashing functio
* Remove unnecessary includes
* Add required include
* Update python dependencies
* Fine-tune kappa mapping parameters
* Fine-tune CNIF beta parameters
* Fix fallback counter error
* Move to libllama and unmap weights offloaded to backend
* Remove unmap weights offloaded to backend
* Add winsorization
* Add adaptive tensor boosting
* Minor cosmetic changes
* Refactor processing of unused kv tensors
* Minor cosmetic change
* Implement --max-buffer-size in target_bpw_type()
* Fix 32-block fallback case
* tensor_type_override_for() DRY refactoring
* Fix typo and remove unused option
* Fix #28491 linking bug when compiling with BUILD_SHARED_LIBS=OFF
* Remove GGML_USE_METAL conditional macro and let the optimizer decide\
* Add --target-exclude
* Remove and ignore uv.lock
* Fix pinned tensors safety limits calculation
* Fix truncation error
* Add downwards greedy upgrade
* Add target bpw/size tests
* Guard imatrix schema
* Update --target-bpw/size descriptions and README.md
* Harden state checkpoint's file operations
* Link model and imatrix to state checkpoint
* Enforce and consume stats schema data
* Add stats schema tests
* Refactor signal handlers out of lib and harden the logic
* Improve handling of pinned tensors
* Add tests
* Add include to keep ubuntu-webgpu happy
* Moving new API entries to prevent brittle downstream apps failing
* Fix miscellaneous issues