Skip to content

Commit 15d395e

Browse files
galrotemfacebook-github-bot
authored andcommitted
fix ao import (#1043)
Summary: Fix dep issue with torchao Reviewed By: vkuzo Differential Revision: D92006625
1 parent 966a402 commit 15d395e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

torchtnt/framework/_loop_utils.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@
1111

1212
import torch
1313
import torch.nn as nn
14-
import torchao
1514
from torch.nn.parallel.distributed import DistributedDataParallel
1615

1716
_EXPORT_UTILS_AVAIL = True
1817
try:
18+
from torchao.quantization.pt2e import (
19+
move_exported_model_to_eval,
20+
move_exported_model_to_train,
21+
)
1922
from torchao.quantization.pt2e.export_utils import model_is_exported
2023
except Exception:
2124
_EXPORT_UTILS_AVAIL = False
2225

26+
def model_is_exported(model: nn.Module) -> bool:
27+
return False
28+
29+
def move_exported_model_to_eval(model: nn.Module) -> None:
30+
pass
31+
32+
def move_exported_model_to_train(model: nn.Module) -> None:
33+
pass
34+
35+
2336
from torchtnt.utils.progress import Progress
2437

2538
_logger: logging.Logger = logging.getLogger(__name__)
@@ -102,9 +115,7 @@ def _set_module_training_mode(
102115
else module
103116
):
104117
move_fn = (
105-
torchao.quantization.pt2e.move_exported_model_to_train
106-
if mode
107-
else torchao.quantization.pt2e.move_exported_model_to_eval
118+
move_exported_model_to_train if mode else move_exported_model_to_eval
108119
)
109120
# pyre-fixme[6]: For 1st argument expected `GraphModule` but got
110121
# `Union[Module, Tensor]`.
@@ -137,9 +148,9 @@ def _reset_module_training_mode(
137148
else module
138149
):
139150
move_fn = (
140-
torchao.quantization.pt2e.move_exported_model_to_train
151+
move_exported_model_to_train
141152
if prior_modes[name]
142-
else torchao.quantization.pt2e.move_exported_model_to_eval
153+
else move_exported_model_to_eval
143154
)
144155
# pyre-fixme[6]: For 1st argument expected `GraphModule` but got
145156
# `Union[Module, Tensor]`.

0 commit comments

Comments
 (0)