llmcompressor.modifiers.gptq.helpers
Classes:
-
FusedQuantType–Numeric quantizer identifiers consumed by the fused GPTQ Triton kernel.
Functions:
-
accumulate_hessian–Accumulate one module-input batch into its GPTQ Hessian statistics.
-
apply_activation_ordering–Reorder weight columns and both Hessian axes by descending activation.
-
assign_batches–Partition modules into compatible GPTQ execution batches based on
-
batch_key–Return the shape, device, dtype, and qparam key needed to share a batch.
-
column_scale_window–Expand qparams into effective per-row, per-column values for a block.
-
factorize_hessian–Dampen and factorize Hessians in place into GPTQ update factors.
-
get_triton_gptq_config–Map supported qargs to fused-kernel type and numeric code range.
-
make_empty_hessian–Allocate the FP32 square Hessian accumulator for a module's input width.
-
max_batch_size–Return the safe batch cap for one representative compatible module.
-
prepare_batch–Build disposable stacked GPTQ inputs and consume per-module statistics.
-
update_batch_qparams–Write a batch's quantized weights and qparams back to its modules.
FusedQuantType
Numeric quantizer identifiers consumed by the fused GPTQ Triton kernel.
accumulate_hessian
accumulate_hessian(
inp: Tensor,
module: Module,
hessian: Tensor,
num_samples: Tensor,
) -> tuple[torch.Tensor, torch.Tensor]
Accumulate one module-input batch into its GPTQ Hessian statistics.
The Hessian and sample counter are updated in place and returned for the
hook caller to retain. Linear, Conv1D, and Conv2d inputs are reshaped into
the common [input_features, observations] representation first.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
apply_activation_ordering
apply_activation_ordering(
weights: Tensor,
hessians: Tensor,
actorder: ActivationOrdering | None,
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor | None]
Reorder weight columns and both Hessian axes by descending activation.
The supplied working tensors are overwritten in place. The returned permutation is used to restore the quantized weights' original order.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
assign_batches
assign_batches(
module_list: list[Module],
batched_quantization: str | int | None,
block_size: int,
) -> list[list[torch.nn.Module]]
Partition modules into compatible GPTQ execution batches based on having the same batch_key.
None produces singleton batches; an integer caps every compatible
batch; and "auto" derives a cap from the available CUDA memory.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
batch_key
Return the shape, device, dtype, and qparam key needed to share a batch.
Return None for modules without a compatible two-dimensional weight or
quantization configuration, forcing them into a singleton batch.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
column_scale_window
column_scale_window(
scale: Tensor,
zero_point: Tensor | None,
global_scale: Tensor | None,
g_idx: Tensor | None,
quant_args: QuantizationArgs,
num_rows: int,
i1: int,
i2: int,
) -> tuple[torch.Tensor, torch.Tensor | None]
Expand qparams into effective per-row, per-column values for a block.
Supports tensor, channel, group, tensor-group, and block qparam layouts; folds in the optional global scale; and returns tensors consumable by both the eager and Triton GPTQ block-update implementations.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
factorize_hessian
factorize_hessian(
weights: Tensor,
hessians: Tensor,
percdamp: float,
used_rtn_fallback: Tensor,
) -> torch.Tensor
Dampen and factorize Hessians in place into GPTQ update factors.
Dead columns are zeroed in weights. Non-positive-definite Hessians are
replaced with identity factors and marked for RTN fallback. Small batches
use per-item linear algebra because it is faster than batched CUDA calls.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
get_triton_gptq_config
Map supported qargs to fused-kernel type and numeric code range.
Return None when the registered Triton block-update backend cannot
represent the requested quantization scheme.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
make_empty_hessian
Allocate the FP32 square Hessian accumulator for a module's input width.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
max_batch_size
Return the safe batch cap for one representative compatible module.
An explicit integer cap bypasses memory estimation. "auto" reserves
75% of currently free CUDA memory for the largest estimated GPTQ phase.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
prepare_batch
prepare_batch(
batch: list[Module],
batch_qparams: list[dict[str, Tensor]],
hessians_by_module: dict[Module, Tensor],
num_samples_by_module: dict[Module, Tensor],
) -> tuple[
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor,
torch.Tensor | None,
]
Build disposable stacked GPTQ inputs and consume per-module statistics.
Removes each module's accumulated Hessian and sample count from the passed
dictionaries, normalizes its Hessian, and stacks it with weights and
observer qparams for a single call to quantize_weight.
Source code in src/llmcompressor/modifiers/gptq/helpers.py
update_batch_qparams
update_batch_qparams(
modules: list[Module],
quantized: Tensor,
scales: Tensor,
zero_points: Tensor,
global_scales: Tensor | None,
quant_args: QuantizationArgs,
) -> None
Write a batch's quantized weights and qparams back to its modules.
update_offload_parameter preserves offload-cache semantics while each
stacked result is cast to the module's storage dtype.