We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 109c010 commit d7aef93Copy full SHA for d7aef93
1 file changed
modelopt/torch/opt/dynamic.py
@@ -584,6 +584,14 @@ def export(self) -> nn.Module:
584
assert not is_dynamic, "Exported module must not be a DynamicModule anymore!"
585
delattr(self, "_dm_attribute_manager")
586
587
+ # If this module had a monkey-patched forward before DynamicModule.convert(), we may have
588
+ # overridden it by binding the dynamic forward onto the instance (to follow the MRO).
589
+ # On final export, restore the original forward to avoid leaking a dynamic forward
590
+ # (e.g., DistillationModel.forward) onto the exported (non-dynamic) module instance.
591
+ if hasattr(self, "_forward_pre_dm"):
592
+ setattr(self, "forward", getattr(self, "_forward_pre_dm"))
593
+ delattr(self, "_forward_pre_dm")
594
+
595
return self
596
597
@classmethod
0 commit comments