Repository navigation
[quantization] Refactor quantization API - #1763
Conversation
59d5a8c to
c1e6450
Compare
87bbaf8 to
82b74e7
Compare
| ) | ||
|
|
||
|
|
||
| def is_quantization_converter(converter: str): |
There was a problem hiding this comment.
no need to have this function, as it's only used in one line
bf9fe65 to
3200b58
Compare
3200b58 to
cab56e4
Compare
cab56e4 to
1d97767
Compare
1d97767 to
2dfaa27
Compare
ce029c7 to
db1903c
Compare
| expert_parallel_degree: int = 1 | ||
| """ | ||
| Expert parallelism degree. 1 means disabled. No effect for non-MoE models. | ||
| Expert parallelism degree. 1 means disabled. No effect for non-GroupedMMConfig models. |
| expert_tensor_parallel_degree: int = 1 | ||
| """ | ||
| Expert tensor parallelism degree. 1 means disabled. No effect for non-MoE models, or when ep = 1. | ||
| Expert tensor parallelism degree. 1 means disabled. No effect for non-GroupedMMConfig models, or when ep = 1. |
| --quantize.dense.float8.enable_fsdp_float8_all_gather \ | ||
| --quantize.dense.float8.precompute_float8_dynamic_scale_for_fsdp \ | ||
| --quantize.dense.float8.force_recompute_fp8_weight_in_bwd \ | ||
| --model.converters="quantize.linear.fp8" \ |
There was a problem hiding this comment.
Not sure if we should change this, as user won't be able to fetch the old package and still run it with new commands.
I think it's OK to change, but let's add a warning for the breakage.
|
|
||
| @dataclass | ||
| class Float8Dense: | ||
| class FP8LinearConfig: |
There was a problem hiding this comment.
Should this still be Float8Linear to be consistent with torchao? The same for all other fp8, should they still be float8? Anyway I saw that you didn't change the file name float8.py.
There was a problem hiding this comment.
I considered this as well, I actually would prefer to change the name in torchao, since it is inconsistent to call every recipe by the abbreviated names (mxfp8/mxfp4/nvfp4/etc) but only call float8 by the fully spelled out name.
Secondarily, I'm also a bit concerned about this API getting too verbose, e.g. --quantize.grouped_mm.float8.recipe_name so trying to make things more concise (i.e., GroupedGEMM -> GroupedMM, Float8 -> FP8)
There was a problem hiding this comment.
on second thought, there's already multiple blogs and tutorials etc out there all using "float8" ... I think it would be worse to potentially confuse or add friction to all future readers of those blogs by changing torchao feature/API to use "fp8" ... I'll just keep it Float8* here
| class Dense: | ||
| float8: Float8Dense = field(default_factory=Float8Dense) | ||
| """Float8 training config for dense layers""" | ||
| class LinearConfig: |
There was a problem hiding this comment.
In terms of style, we shouldn't add the Config suffix to the configs. This is only trying to be consistent -- I can imagine a repo where all configs have the config suffix.
Also to make them meaningful, we probably should use QuantizeLinear instead of just Linear.
There was a problem hiding this comment.
I thought about this too but "XYZLinear" is the common naming convention for actual nn.Linear subclass using XYZ customization - not just in torchao, but in other codebases as well.
So it sounds like it's a linear layer, and I wanted the difference between Linear configs and the Linear layer to be clear from the naming.
I don't have strong opinions on this though, just sharing context. I am fine with making it QuantizedLinear and removing Config suffixes.
e7f3b6a to
6421f83
Compare
There was a problem hiding this comment.
Thanks, accidentally had ~/torchtitan/torchtitan open instead of ~torchtitan/, so replace all missed these other dirs.
| class Dense: | ||
| float8: Float8Dense = field(default_factory=Float8Dense) | ||
| """Float8 training config for dense layers""" | ||
| class QuantizedLinear: |
There was a problem hiding this comment.
I thought about this too but "XYZLinear" is the common naming convention for actual nn.Linear subclass using XYZ customization - not just in torchao, but in other codebases as well.
So it sounds like it's a linear layer, and I wanted the difference between Linear configs and the Linear layer to be clear from the naming.
I don't have strong opinions on this though, just sharing context. I am fine with making it QuantizedLinear and remove Config suffixes.
Good point. Given they are not supposed to be actually used by users, I think it's fine for now to do it this way today. Let's see how things goes.
## Summary - Float8 training and mx training cannot be combined. Add validation to ensure either one or the other is used. - Fix tomls which still use old config naming (addresses pytorch#1764) - Refactor quantization config naming so (1) job_config class names are consistent with converter names, and (2) naming is more explicit and aligned with semantics of what conversions actually happen - Old: - Converter classes: - `Float8Converter` - `Float8MoEConverter` - `MXConverter` - `MXMoEConverter` - User-facing args: - `quantize.dense.float8` - `quantize.moe.float8` - `quantize.dense.mx` - `quantize.moe.mx` - New: - Converter classes: - `Float8LinearConverter` - `Float8GroupedGEMMConverter` - `MXLinearConverter` - `MXGroupedGEMMConverter` - User-facing args: - `quantize.linear.float8` - `quantize.grouped_mm.float8` - `quantize.linear.mx` - `quantize.grouped_mm.mx` ## Tests: mx on B200 - Test new config/args with valid job: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.mx,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.groupe d_mm.mx.fqns="experts" --compile.enable` - Result: training as expected - Test mixing converters for different quantization methods, validate error: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.fp8,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.grouped_mm.mx.fqns="experts" --compile.enable` - Result `AssertionError: Cannot combine model converters with different quantization types: 'mx' and 'fp8'` ## Tests: FP8 rowwise on H100 - Test new config/args with valid job: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.float8,quantize.grouped_mm.float8" --quantize.linear.float8.recipe_name="rowwise" --quantize.grouped_mm.float8.fqns="experts" --compile.enable` - Result: training as expected
## Summary - Float8 training and mx training cannot be combined. Add validation to ensure either one or the other is used. - Fix tomls which still use old config naming (addresses pytorch#1764) - Refactor quantization config naming so (1) job_config class names are consistent with converter names, and (2) naming is more explicit and aligned with semantics of what conversions actually happen - Old: - Converter classes: - `Float8Converter` - `Float8MoEConverter` - `MXConverter` - `MXMoEConverter` - User-facing args: - `quantize.dense.float8` - `quantize.moe.float8` - `quantize.dense.mx` - `quantize.moe.mx` - New: - Converter classes: - `Float8LinearConverter` - `Float8GroupedGEMMConverter` - `MXLinearConverter` - `MXGroupedGEMMConverter` - User-facing args: - `quantize.linear.float8` - `quantize.grouped_mm.float8` - `quantize.linear.mx` - `quantize.grouped_mm.mx` ## Tests: mx on B200 - Test new config/args with valid job: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.mx,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.groupe d_mm.mx.fqns="experts" --compile.enable` - Result: training as expected - Test mixing converters for different quantization methods, validate error: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.fp8,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.grouped_mm.mx.fqns="experts" --compile.enable` - Result `AssertionError: Cannot combine model converters with different quantization types: 'mx' and 'fp8'` ## Tests: FP8 rowwise on H100 - Test new config/args with valid job: - `NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.float8,quantize.grouped_mm.float8" --quantize.linear.float8.recipe_name="rowwise" --quantize.grouped_mm.float8.fqns="experts" --compile.enable` - Result: training as expected
Summary
Float8ConverterFloat8MoEConverterMXConverterMXMoEConverterquantize.dense.float8quantize.moe.float8quantize.dense.mxquantize.moe.mxFloat8LinearConverterFloat8GroupedGEMMConverterMXLinearConverterMXGroupedGEMMConverterquantize.linear.float8quantize.grouped_mm.float8quantize.linear.mxquantize.grouped_mm.mxTests: mx on B200
NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.mx,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.groupe d_mm.mx.fqns="experts" --compile.enableNGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.fp8,quantize.grouped_mm.mx" --quantize.linear.mx.recipe_name="mxfp8_cublas" --quantize.grouped_mm.mx.fqns="experts" --compile.enableAssertionError: Cannot combine model converters with different quantization types: 'mx' and 'fp8'Tests: FP8 rowwise on H100
NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=1 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.linear.float8,quantize.grouped_mm.float8" --quantize.linear.float8.recipe_name="rowwise" --quantize.grouped_mm.float8.fqns="experts" --compile.enable