Add NVFP4 QAT#2666
Merged
Merged
Conversation
**Summary:** The existing `FakeQuantizeConfig` performs only intx quantization, but we plan to extend QAT to other dtypes such as fp8 and nvfp4 in the near future. This is the necessary refactor before that. Specifically: ``` # New abstract class FakeQuantizeConfigBase # Rename FakeQuantizeConfig -> IntxFakeQuantizeConfig ``` In the future, we will have other types of `FakeQuantizeConfigBase` for float dtypes that users can pass in instead of the existing Intx one. **BC-breaking notes:** For BC, we keep around the old names to reference the new ones. However, this commit is still BC-breaking in the sense that a few APIs now accept the abstract `FakeQuantizeConfigBase` instead. For the most part, this abstract class will be hidden from the user. Before: ``` activation_config = FakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False) weight_config = FakeQuantizeConfig(torch.int4, group_size=32) ``` After: ``` activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False) weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32) ``` **Test Plan:** python test/quantization/test_qat.py [ghstack-poisoned]
**Summary:** This commit adds a new multi-step QAT API with the
main goal of simplifying the existing UX. The new API uses the
same `QATConfig` for both the prepare and convert steps, and
automatically infers the fake quantization configs based on
a PTQ base config provided by the user:
```
from torchao.quantization import (
quantize_,
Int8DynamicActivationInt4WeightConfig
)
from torchao.quantization.qat import QATConfig
\# prepare
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
qat_config = QATConfig(base_config, step="prepare")
quantize_(m, qat_config)
\# train (not shown)
\# convert
quantize_(m, QATConfig(base_config, step="convert"))
```
The main improvements include:
- A single config for both prepare and convert steps
- A single quantize_ for convert (instead of 2)
- No chance for incompatible prepare vs convert configs
- Much less boilerplate code for most common use case
- Simpler config names
For less common use cases such as experimentation, users can
still specify arbitrary fake quantization configs for
activations and/or weights as before. This is still important
since there may not always be a corresponding PTQ base config.
For example:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import IntxFakeQuantizeConfig, QATConfig
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
\# train and convert same as above (not shown)
```
**BC-breaking notes:** This change by itself is technically not
BC-breaking since we keep around the old path, but will become
so when we deprecate and remove the old path in the future.
Before:
```
\# prepare
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = IntXQuantizationAwareTrainingConfig(activation_config, weight_config),
quantize_(model, qat_config)
\# train (not shown)
\# convert
quantize_(model, FromIntXQuantizationAwareTrainingConfig())
quantize_(model, Int8DynamicActivationInt4WeightConfig(group_size=32))
```
After: (see above)
**Test Plan:**
```
python test/quantization/test_qat.py
```
[ghstack-poisoned]
**Summary:** This commit adds a new multi-step QAT API with the
main goal of simplifying the existing UX. The new API uses the
same `QATConfig` for both the prepare and convert steps, and
automatically infers the fake quantization configs based on
a PTQ base config provided by the user:
```
from torchao.quantization import (
quantize_,
Int8DynamicActivationInt4WeightConfig
)
from torchao.quantization.qat import QATConfig
# prepare
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(m, QATConfig(base_config, step="prepare"))
# train (not shown)
# convert
quantize_(m, QATConfig(base_config, step="convert"))
```
The main improvements include:
- A single config for both prepare and convert steps
- A single quantize_ for convert (instead of 2)
- No chance for incompatible prepare vs convert configs
- Much less boilerplate code for most common use case
- Simpler config names
For less common use cases such as experimentation, users can
still specify arbitrary fake quantization configs for
activations and/or weights as before. This is still important
since there may not always be a corresponding PTQ base config.
For example:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import IntxFakeQuantizeConfig, QATConfig
# prepare
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
# train and convert same as above (not shown)
```
**BC-breaking notes:** This change by itself is technically not
BC-breaking since we keep around the old path, but will become
so when we deprecate and remove the old path in the future.
Before:
```
# prepare
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = IntXQuantizationAwareTrainingConfig(activation_config, weight_config),
quantize_(model, qat_config)
# train (not shown)
# convert
quantize_(model, FromIntXQuantizationAwareTrainingConfig())
quantize_(model, Int8DynamicActivationInt4WeightConfig(group_size=32))
```
After: (see above)
**Test Plan:**
```
python test/quantization/test_qat.py
```
[ghstack-poisoned]
**Summary:** This commit adds a new multi-step QAT API with the
main goal of simplifying the existing UX. The new API uses the
same `QATConfig` for both the prepare and convert steps, and
automatically infers the fake quantization configs based on
a PTQ base config provided by the user:
```
from torchao.quantization import (
quantize_,
Int8DynamicActivationInt4WeightConfig
)
from torchao.quantization.qat import QATConfig
# prepare
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(m, QATConfig(base_config, step="prepare"))
# train (not shown)
# convert
quantize_(m, QATConfig(base_config, step="convert"))
```
The main improvements include:
- A single config for both prepare and convert steps
- A single quantize_ for convert (instead of 2)
- No chance for incompatible prepare vs convert configs
- Much less boilerplate code for most common use case
- Simpler config names
For less common use cases such as experimentation, users can
still specify arbitrary fake quantization configs for
activations and/or weights as before. This is still important
since there may not always be a corresponding PTQ base config.
For example:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import IntxFakeQuantizeConfig, QATConfig
# prepare
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
# train and convert same as above (not shown)
```
**BC-breaking notes:** This change by itself is technically not
BC-breaking since we keep around the old path, but will become
so when we deprecate and remove the old path in the future.
Before:
```
# prepare
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = IntXQuantizationAwareTrainingConfig(activation_config, weight_config),
quantize_(model, qat_config)
# train (not shown)
# convert
quantize_(model, FromIntXQuantizationAwareTrainingConfig())
quantize_(model, Int8DynamicActivationInt4WeightConfig(group_size=32))
```
After: (see above)
**Test Plan:**
```
python test/quantization/test_qat.py
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used. Print helpful deprecation warning to help users migrate. **Test Plan:** ``` python test/quantization/test_qat.py -k test_qat_api_deprecation ``` [ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used. Print helpful deprecation warning to help users migrate. **Test Plan:** ``` python test/quantization/test_qat.py -k test_qat_api_deprecation ``` [ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used. Print helpful deprecation warning to help users migrate. **Test Plan:** ``` python test/quantization/test_qat.py -k test_qat_api_deprecation ``` [ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** Deprecates QAT APIs that should no longer be used.
Print helpful deprecation warning to help users migrate.
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_api_deprecation
```
Also manual testing:
```
>>> from torchao.quantization.qat import IntXQuantizationAwareTrainingConfig
>>> IntXQuantizationAwareTrainingConfig()
'IntXQuantizationAwareTrainingConfig' is deprecated and will be removed in a future release. Please use the following API instead:
base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
quantize_(model, QATConfig(base_config, step="prepare"))
# train (not shown)
quantize_(model, QATConfig(base_config, step="convert"))
Alternatively, if you prefer to pass in fake quantization configs:
activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
qat_config = QATConfig(
activation_config=activation_config,
weight_config=weight_config,
step="prepare",
)
quantize_(model, qat_config)
Please see #2630 for more details.
IntXQuantizationAwareTrainingConfig(activation_config=None, weight_config=None)
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
[ghstack-poisoned]
This was referenced Aug 1, 2025
Merged
Merged
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2666
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Cancelled JobAs of commit a024e29 with merge base bc2c83e ( NEW FAILURE - The following job has failed:
CANCELLED JOB - The following job was cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
andrewor14
added a commit
that referenced
this pull request
Aug 1, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
ghstack-source-id: fe592ca
Pull Request resolved: #2666
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 5548756
Pull Request resolved: #2666
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 5548756
Pull Request resolved: #2666
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 5548756
Pull Request resolved: #2666
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
[ghstack-poisoned]
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 8c7d051
Pull Request resolved: #2666
drisspg
reviewed
Aug 22, 2025
drisspg
reviewed
Aug 22, 2025
| per_tensor_scale = None | ||
|
|
||
| # quantize | ||
| scale, q = _nvfp4_quantize( |
Contributor
Author
There was a problem hiding this comment.
added STE instead (see _Float8Round)
drisspg
reviewed
Aug 22, 2025
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 5548756
Pull Request resolved: #2666
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
[ghstack-poisoned]
andrewor14
added a commit
that referenced
this pull request
Aug 22, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on oasst1 for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7927|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7323|± | N/A|
| | |none |None |word_perplexity|↓ |18.8815|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.7921|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7316|± | N/A|
| | |none |None |word_perplexity|↓ |18.8409|± | N/A|
```
ghstack-source-id: 512c7c2
Pull Request resolved: #2666
jerryzh168
reviewed
Aug 23, 2025
Comment on lines
+116
to
+117
| if x.dim() == 3: | ||
| x = x.view(-1, x.shape[-1]) |
Contributor
There was a problem hiding this comment.
why does this happen here? can this happen in quant primtive ops?
Contributor
Author
There was a problem hiding this comment.
I found that this was necessary for activations during training (for the batch size). Not sure if it was necessary for inference? @drisspg
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: 5548756
Pull Request resolved: #2666
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: 5ddda63
Pull Request resolved: #2666
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: 5ddda63
Pull Request resolved: #2666
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: fb5c617
Pull Request resolved: #2666
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: fb5c617
Pull Request resolved: #2666
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
activation_config=NVFP4FakeQuantizeConfig(),
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
[ghstack-poisoned]
andrewor14
added a commit
that referenced
this pull request
Aug 25, 2025
**Summary:** This commit adds a QAT flow for NVFP4, following the
numerics in `NVFP4Tensor` closely but without the dtyping casting,
swizzling, and the packing/unpacking. Users can call this flow as follows:
```
from torchao.quantization import quantize_
from torchao.quantization.qat import NVFP4FakeQuantizeConfig, QATConfig
qat_config = QATConfig(
weight_config=NVFP4FakeQuantizeConfig(),
step="prepare",
)
quantize_(model, qat_config)
```
**Test Plan:**
```
python test/quantization/test_qat.py -k test_qat_nvfp4
```
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs:
```
# Without QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8322|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7804|± | N/A|
| | |none |None |word_perplexity|↓ |21.8611|± | N/A|
# With QAT
| Tasks |Version|Filter|n-shot| Metric | | Value | |Stderr|
|--------|------:|------|------|---------------|---|------:|---|------|
|wikitext| 2|none |None |bits_per_byte |↓ | 0.8271|± | N/A|
| | |none |None |byte_perplexity|↓ | 1.7741|± | N/A|
| | |none |None |word_perplexity|↓ |21.4467|± | N/A|
```
ghstack-source-id: 3e1b617
Pull Request resolved: #2666
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Summary: This commit adds a QAT flow for NVFP4, following the
numerics in
NVFP4Tensorclosely but without the dtyping casting,swizzling, and the packing/unpacking. Users can call this flow as follows:
Test Plan:
Initial benchmarks on fine-tuning Qwen3-1.7B on alpaca for 3 epochs: