Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace replace calls to model.train() for executorch models #731

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 12 additions & 1 deletion torchtnt/framework/_loop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import torch
import torch.nn as nn
import typing_extensions
from torch.nn.parallel.distributed import DistributedDataParallel

from torchtnt.framework.state import State
from torchtnt.utils.progress import Progress

Expand Down Expand Up @@ -59,7 +61,16 @@ def _set_module_training_mode(
prior_module_train_states = {}
for name, module in modules.items():
prior_module_train_states[name] = module.training
module.train(mode)
if isinstance(module, DistributedDataParallel):
module = module.module
if torch.ao.quantization.pt2e.export_utils.model_is_exported(module):
if mode:
module = torch.ao.quantization.move_exported_model_to_train(module)
else:
module = torch.ao.quantization.move_exported_model_to_eval(module)
else:
module.train(mode)

return prior_module_train_states


Expand Down
Loading