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
20 changes: 15 additions & 5 deletions primus/backends/megatron/core/extensions/primus_turbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,9 @@ def forward_internal(

if get_num_microbatches() == 1:
if is_first_microbatch:
self.quantized_weight_buffer = torch.empty(0, device=weight.device, dtype=torch.uint8)
self.quantized_weight_buffer = torch.empty(
0, device=weights.device, dtype=float4_e2m1fn_x2
)
Comment on lines +1150 to +1152
out = primus_turbo_torch.ops.gemm_fp4(
x,
weight,
Expand Down Expand Up @@ -1358,7 +1360,9 @@ def forward_internal(

if get_num_microbatches() == 1:
if is_first_microbatch:
self.quantized_weight_buffer = torch.empty(0, device=weight.device, dtype=torch.uint8)
self.quantized_weight_buffer = torch.empty(
0, device=weights.device, dtype=float4_e2m1fn_x2
)
out = primus_turbo_torch.ops.gemm_fp4(
x,
weight,
Expand Down Expand Up @@ -1562,7 +1566,9 @@ def forward_internal(

if get_num_microbatches() == 1:
if is_first_microbatch:
self.quantized_weight_buffer = torch.empty(0, device=weight.device, dtype=torch.uint8)
self.quantized_weight_buffer = torch.empty(
0, device=weights.device, dtype=float4_e2m1fn_x2
)
out = primus_turbo_torch.ops.gemm_fp4(
x,
weight,
Expand Down Expand Up @@ -1779,7 +1785,9 @@ def forward_internal(self, x, is_first_microbatch: bool = False):

if get_num_microbatches() == 1:
if is_first_microbatch:
self.quantized_weight_buffer = torch.empty(0, device=weight.device, dtype=torch.uint8)
self.quantized_weight_buffer = torch.empty(
0, device=weights.device, dtype=float4_e2m1fn_x2
)
out = primus_turbo_torch.ops.gemm_fp4(
inp,
weight,
Expand Down Expand Up @@ -2176,7 +2184,9 @@ def forward_internal(
# no persistent cache. Expose a lightweight runtime marker so
# weight de-oscillation can identify the grouped FP4 weight.
if is_first_microbatch:
self.quantized_weight_buffer = torch.empty(0, device=weights.device, dtype=torch.uint8)
self.quantized_weight_buffer = torch.empty(
0, device=weights.device, dtype=float4_e2m1fn_x2
)
out = primus_turbo_torch.ops.grouped_gemm_fp4(
x,
weights,
Expand Down
3 changes: 2 additions & 1 deletion primus/backends/megatron/core/optimizer/weight_deosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def _build_eligible_ids(self, dist_opt) -> set:
for chunk in model_chunks:
modules = chunk.modules() if hasattr(chunk, "modules") else []
for module in modules:
if getattr(module, "quantized_weight_buffer", None) is None:
quantized_weight_buffer = getattr(module, "quantized_weight_buffer", None)
if quantized_weight_buffer is None or quantized_weight_buffer.dtype != _float4_e2m1fn_x2:
continue
Comment on lines +354 to 356
weight = getattr(module, "_parameters", {}).get("weight", None)
if weight is None:
Expand Down
Loading