Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions tests/pytorch/distributed/test_cast_master_weights_to_fp8.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ def _test_mini_optimizer(dp_group):
torch.testing.assert_close(w1, w3, atol=0, rtol=0)


def _test_cast_master_weights_to_fp8(quantization, dp_group, manual_post_all_gather_processing):
def _test_cast_master_weights_to_fp8(
quantization, dp_group, manual_post_all_gather_processing, keep_fp8_weight_transpose_cache
):
rank = dist.get_rank(dp_group)
world_size = dist.get_world_size(dp_group)

Expand All @@ -506,7 +508,12 @@ def _test_cast_master_weights_to_fp8(quantization, dp_group, manual_post_all_gat
mock_groups = [dist.new_group(ranks=[i]) for i in range(world_size)]
mock_group = mock_groups[rank]

linear_kwargs = {"params_dtype": torch.bfloat16, "bias": False, "fuse_wgrad_accumulation": True}
linear_kwargs = {
"params_dtype": torch.bfloat16,
"bias": False,
"fuse_wgrad_accumulation": True,
"keep_fp8_weight_transpose_cache": keep_fp8_weight_transpose_cache,
}

# Create model with FP8 weights
with te.quantized_model_init(
Expand Down Expand Up @@ -583,7 +590,7 @@ def _test_cast_master_weights_to_fp8(quantization, dp_group, manual_post_all_gat


def _test_fsdp_cast_master_weights_to_fp8(
quantization, dp_group, manual_post_all_gather_processing
quantization, dp_group, manual_post_all_gather_processing, keep_fp8_weight_transpose_cache
):
rank = dist.get_rank(dp_group)
world_size = dist.get_world_size(dp_group)
Expand All @@ -602,6 +609,7 @@ def _test_fsdp_cast_master_weights_to_fp8(
"params_dtype": torch.bfloat16,
"bias": False,
"fuse_wgrad_accumulation": True,
"keep_fp8_weight_transpose_cache": keep_fp8_weight_transpose_cache,
}

# Create model with FP8 weights
Expand Down Expand Up @@ -702,13 +710,19 @@ def run_parallel_tests() -> None:
quantizations.append("fp8_block")

manual_post_all_gather_processings = [False, True]
keep_fp8_weight_transpose_caches = [True, False]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be only True on CUDA and better name it keep_fp8_weight_transpose_cache - to match the name of parameter


_test_mini_optimizer(dp_group)

for quantization in quantizations:
for post_ag_processing in manual_post_all_gather_processings:
_test_cast_master_weights_to_fp8(quantization, dp_group, post_ag_processing)
_test_fsdp_cast_master_weights_to_fp8(quantization, dp_group, post_ag_processing)
for keep_fp8_weight_transpose_cache in keep_fp8_weight_transpose_caches:
_test_cast_master_weights_to_fp8(
quantization, dp_group, post_ag_processing, keep_fp8_weight_transpose_cache
)
_test_fsdp_cast_master_weights_to_fp8(
quantization, dp_group, post_ag_processing, keep_fp8_weight_transpose_cache
)

dist.destroy_process_group()

Expand Down
2 changes: 1 addition & 1 deletion transformer_engine/pytorch/tensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def post_all_gather_processing(model_weights: Union[torch.Tensor, List[torch.Ten
if isinstance(model_weight, Float8Tensor):
# Delayed scaling and per-tensor current scaling: if backend does not support
# non-transposed FP8 GEMM, pre-create the transpose.
if not is_non_tn_fp8_gemm_supported():
if model_weight._quantizer.columnwise_usage and not is_non_tn_fp8_gemm_supported():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment or guard the changes

model_weight._create_transpose()
elif isinstance(model_weight, Float8BlockwiseQTensor):
# Blockwise scaling: create column-wise storage.
Expand Down