Skip to content

Commit 8926453

Browse files
authored
magic instance support (#4756)
1 parent 49074a0 commit 8926453

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

paddleformers/trainer/trainer.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,6 +4197,17 @@ def _dataset_process_function():
41974197
with self.autocast_smart_context_manager():
41984198
loss = model.forward_backward_pipeline(inputs, self.scaler if self.do_grad_scaling else None)
41994199

4200+
# MTP magic send: reset per-depth counters after each optimizer step
4201+
if getattr(self.args, "enable_mtp_magic_send", False):
4202+
try:
4203+
from paddlefleet.models.gpt.mtp_embedding_layer import (
4204+
mtp_magic_instance,
4205+
)
4206+
4207+
mtp_magic_instance.clear_count_dict()
4208+
except (ImportError, ModuleNotFoundError):
4209+
pass
4210+
42004211
return loss.detach()
42014212

42024213
def save_model(
@@ -5399,6 +5410,16 @@ def _prepare_inputs_for_fleet(inputs):
53995410
if need_clear:
54005411
if hasattr(model, "_p2p_helper"):
54015412
model._p2p_helper.clear_meta_cache()
5413+
# MTP magic send: reset counters after eval step (shared singleton with train)
5414+
if getattr(self.args, "enable_mtp_magic_send", False):
5415+
try:
5416+
from paddlefleet.models.gpt.mtp_embedding_layer import (
5417+
mtp_magic_instance,
5418+
)
5419+
5420+
mtp_magic_instance.clear_count_dict()
5421+
except (ImportError, ModuleNotFoundError):
5422+
pass
54025423

54035424
return (loss, None, labels)
54045425

0 commit comments

Comments
 (0)