Skip to navigation

nemo_automodel.components.quantization.fp8

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
FP8ConfigConfiguration for FP8 quantization settings.
_FP8ConfigDict-
_FP8ConfigSourceMapping-like FP8 configuration source; ConfigNode satisfies it.
_FP8ConversionStats-
_FP8ModuleInfo-

Functions

NameDescription
_has_cuda_capabilityCheck if CUDA device has required compute capability.
_module_filter_fnFilter function to exclude certain modules from FP8 conversion.
apply_fp8_to_modelApply FP8 quantization to a PyTorch model using torchao.
build_fp8_configBuild a FP8 config from configuration.
create_fp8_config_from_dictCreate a FP8Config from a mapping-like configuration source.
uses_hardware_fp8Return whether TorchAO converted a layer to native FP8 compute.
verify_fp8_conversionVerify that FP8 conversion was successful by counting converted modules.

Data

FP8RecipeName

HAVE_TORCHAO

logger

API

class nemo_automodel.components.quantization.fp8.FP8Config(
enabled: bool = False,
enable_fsdp_float8_all_gather: bool = False,
precompute_float8_dynamic_scale_for_fsdp: bool = False,
force_recompute_fp8_weight_in_bwd: bool = False,
filter_fqns: list[str] | None = None,
emulate: bool = False
)
Dataclass

Configuration for FP8 quantization settings.

filter_fqns
list[str] = filter_fqns or []

List of fully qualified names of modules to skip applying float8 training to. nn.Linear modules with any dim size not divisible by 16 are always skipped due to hardware requirements. Example: [“attention.wq”, “attention.wk”, “attention.wv”, “lm_head”]

nemo_automodel.components.quantization.fp8.FP8Config.to_dict() -> nemo_automodel.components.quantization.fp8._FP8ConfigDict
class nemo_automodel.components.quantization.fp8._FP8ConfigDict

Bases: typing.TypedDict

enable_fsdp_float8_all_gather
bool
enabled
bool
force_recompute_fp8_weight_in_bwd
bool
fp8_emulate
bool
fp8_filter_fqns
list[str]
fp8_recipe_name
FP8RecipeName | None
precompute_float8_dynamic_scale_for_fsdp
bool
class nemo_automodel.components.quantization.fp8._FP8ConfigSource()
Protocol

Mapping-like FP8 configuration source; ConfigNode satisfies it.

class nemo_automodel.components.quantization.fp8._FP8ConversionStats

Bases: typing.TypedDict

conversion_rate
float
fp8_count
int
fp8_modules
list[_FP8ModuleInfo]
linear_count
int
success
bool
class nemo_automodel.components.quantization.fp8._FP8ModuleInfo

Bases: typing.TypedDict

name
str
type
str
weight_shape
list[int] | None
nemo_automodel.components.quantization.fp8._has_cuda_capability(
major: int,
minor: int
) -> bool

Check if CUDA device has required compute capability.

nemo_automodel.components.quantization.fp8._module_filter_fn(
module: torch.nn.Module,
name: str,
filter_fqns: list[str] | None = None
) -> bool

Filter function to exclude certain modules from FP8 conversion.

Parameters:

module
nn.Module

The module to check

name
str

Fully qualified name of the module

filter_fqns
list[str] | NoneDefaults to None

List of FQNs to filter out

Returns: bool

True if module should be converted to FP8, False otherwise

nemo_automodel.components.quantization.fp8.apply_fp8_to_model(
model: torch.nn.Module,
filter_fqns: list[str] | None = None,
force_recompute_fp8_weight_in_bwd: bool = False,
enable_fsdp_float8_all_gather: bool = False,
emulate: bool = False,
enabled: bool = True,
precompute_float8_dynamic_scale_for_fsdp: bool = False
) -> torch.nn.Module

Apply FP8 quantization to a PyTorch model using torchao.

This function can be called in two ways:

  1. With an FP8Config object: apply_fp8_to_model(model, config=fp8_config)
  2. With individual parameters: apply_fp8_to_model(model, filter_fqns=…, recipe_name=…, etc.)

Parameters:

model
nn.Module

The model to convert

config
FP8Config | NoneDefaults to None

FP8Config object containing all configuration. If provided, individual parameters are ignored.

filter_fqns
list[str] | NoneDefaults to None

List of module names to exclude from FP8 conversion

recipe_name
FP8RecipeName | NoneDefaults to None

Recipe name for FP8 configuration (“tensorwise”, “rowwise”, etc.)

force_recompute_fp8_weight_in_bwd
boolDefaults to False

Whether to force recompute FP8 weight in backward pass

enable_fsdp_float8_all_gather
boolDefaults to False

Whether to enable FSDP FP8 all-gather

emulate
boolDefaults to False

Use emulation instead of hardware acceleration (for testing on older GPUs)

enabled
boolDefaults to True

Whether FP8 quantization is enabled (only used when config is None)

precompute_float8_dynamic_scale_for_fsdp
boolDefaults to False

Whether to precompute float8 scales dynamically

Returns: nn.Module

The model with FP8 linear layers (modified in-place)

Raises:

  • ImportError: If torchao is not installed
  • ValueError: If hardware doesn’t support FP8 and emulation is disabled
nemo_automodel.components.quantization.fp8.build_fp8_config(

Build a FP8 config from configuration.

Parameters:

cfg
_FP8ConfigSource | None

Configuration source for FP8 quantization. None returns a disabled config.

Returns: FP8Config

FP8Config instance.

nemo_automodel.components.quantization.fp8.create_fp8_config_from_dict(

Create a FP8Config from a mapping-like configuration source.

Parameters:

config_dict
_FP8ConfigSource

Configuration source for FP8 quantization. A ConfigNode satisfies this protocol.

Returns: FP8Config

FP8Config instance.

nemo_automodel.components.quantization.fp8.uses_hardware_fp8(
model: torch.nn.Module
) -> bool

Return whether TorchAO converted a layer to native FP8 compute.

nemo_automodel.components.quantization.fp8.verify_fp8_conversion(
model: torch.nn.Module

Verify that FP8 conversion was successful by counting converted modules.

Parameters:

model
nn.Module

The model to verify

Returns: _FP8ConversionStats

Dict with conversion statistics

nemo_automodel.components.quantization.fp8.FP8RecipeName = Literal['tensorwise', 'rowwise', 'rowwise_with_gw_hp']
nemo_automodel.components.quantization.fp8.HAVE_TORCHAO = True
nemo_automodel.components.quantization.fp8.logger = logging.getLogger(__name__)