Skip to content
Merged
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
8 changes: 4 additions & 4 deletions swift/megatron/utils/convert_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def broadcast_mg_logits(mg_logits=None, src_rank=None):


@contextmanager
def _patch_attention_flash_fp32(compute_dtype):
def _patch_attention_fp32(compute_dtype):
forward = TEDotProductAttention.forward

def new_forward(self, query_layer, key_layer, value_layer, *args, **kwargs):
Expand Down Expand Up @@ -252,11 +252,11 @@ def test_convert_precision(args, hf_model, mg_model, template, test_convert_dtyp
for n, m in mg_language_model.named_modules():
if n.endswith('router'):
m.to(mg_dtype)
attention_flash_context = (
_patch_attention_flash_fp32(mg_dtype) if args.attention_backend.name == 'flash' else nullcontext())
attention_context = (
_patch_attention_fp32(mg_dtype) if args.attention_backend.name in {'flash', 'fused'} else nullcontext())
Comment thread
Jintao-Huang marked this conversation as resolved.
with torch.inference_mode(), _model_cpu_forward_context(
mg_modules, test_convert_dtype, 'cuda', share_embedding=share_embedding,
target_device=mg_device), attention_flash_context:
target_device=mg_device), attention_context:
mg_logits = forward_step_helper(mg_model, mg_inputs, dtype=test_convert_dtype)
if args.tensor_model_parallel_size > 1 and args.task_type != 'seq_cls':
if mg_logits is not None:
Expand Down
Loading