Skip to content

Added warnings if the model is in training mode #3676

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions py/torch_tensorrt/dynamo/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,10 @@ def compile_module(
Returns:
Compiled FX GraphModule
"""
if any(v.requires_grad for v in gm.state_dict().values()):
logger.warning(
"The model may be in training mode, which may affect the performance of the compiled model!"
)
dryrun_tracker = DryRunTracker()
if sample_kwarg_inputs is None:
sample_kwarg_inputs = {}
Expand Down
12 changes: 8 additions & 4 deletions py/torch_tensorrt/dynamo/runtime/_MutableTorchTensorRTModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from copy import deepcopy
from enum import Enum, auto
from typing import Any, Dict, Iterator, Optional, Set, Union
from typing import Any, Dict, Iterator, Optional, Set, Tuple, Union

import numpy as np
import torch
Expand Down Expand Up @@ -70,7 +70,9 @@ def __init__(
strict: bool = True,
allow_complex_guards_as_runtime_asserts: bool = False,
weight_streaming_budget: Optional[int] = None,
enabled_precisions: Optional[Set[Union[torch.dtype, dtype]]] = None,
enabled_precisions: Union[
Set[Union[torch.dtype, dtype]], Tuple[Union[torch.dtype, dtype]]
] = _defaults.ENABLED_PRECISIONS,
**kwargs: Any,
) -> None:
"""
Expand Down Expand Up @@ -128,6 +130,10 @@ def __init__(
self.refit_state = RefitState()
self.pytorch_model = _make_refit_change_trigger(pytorch_model, self.refit_state)
self.original_model = pytorch_model
if pytorch_model.training:
logger.warning(
"The model may be in training mode, which may affect the performance of the compiled model!"
)
# Process settings
self.gm: Any = None
self.exp_program: Any = None
Expand Down Expand Up @@ -163,8 +169,6 @@ def __init__(
"Weight stremaing budget is not set. Using auto weight streaming budget"
)
self.enabled_precisions = enabled_precisions
if self.enabled_precisions is None:
self.enabled_precisions = _defaults.ENABLED_PRECISIONS

cls = self.__class__
self.__class__ = type(
Expand Down
Loading