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
7 changes: 6 additions & 1 deletion transformer_engine/pytorch/csrc/quantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,13 @@ std::pair<TensorWrapper, py::object> MXFP8Quantizer::create_tensor(
if (columnwise_usage) {
const std::vector<int64_t> scale_inv_shape_int64(columnwise_scale_inv_shape.begin(),
columnwise_scale_inv_shape.end());
columnwise_data_tensor = at::empty(shape_int64, uint8_tensor_opts);
columnwise_scale_inv_tensor = at::empty(scale_inv_shape_int64, uint8_tensor_opts);
if (with_2d_quantization && rowwise_usage) {
// 2D quantization: rowwise and columnwise data are identical, share the buffer
columnwise_data_tensor = rowwise_data_tensor;
} else {
columnwise_data_tensor = at::empty(shape_int64, uint8_tensor_opts);
}
}

// Convert tensors to Python
Expand Down
13 changes: 12 additions & 1 deletion transformer_engine/pytorch/tensor/mxfp8_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def inner_tensor_specs(
torch.uint8,
)
if self.columnwise_usage:
specs["_columnwise_data"] = (shape, torch.uint8)
# 2D quantization: data is identical, reuse rowwise_data instead of allocating a copy
if not (self.with_2d_quantization and self.rowwise_usage):
specs["_columnwise_data"] = (shape, torch.uint8)
specs["_columnwise_scale_inv"] = (
tuple(self.get_scale_shape(shape, columnwise=True)),
torch.uint8,
Expand Down Expand Up @@ -263,6 +265,15 @@ def __new__(
with_gemm_swizzled_scales: bool,
**kwargs,
):
# 2D quantization: columnwise data is identical to rowwise, alias it
if (
columnwise_data is None
and rowwise_data is not None
and quantizer is not None
and getattr(quantizer, "with_2d_quantization", False)
and getattr(quantizer, "columnwise_usage", False)
):
columnwise_data = rowwise_data
Comment thread
greptile-apps[bot] marked this conversation as resolved.
return super().__new__(
cls,
rowwise_data,
Expand Down