Skip to content

Commit

Permalink
DisableCompileContextManager definition
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Dec 19, 2024
1 parent 31093a2 commit d33710d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions optimum/exporters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,15 @@ def _get_submodels_and_export_configs(
export_config = next(iter(models_and_export_configs.values()))[1]

return export_config, models_and_export_configs


class DisableCompileContextManager:
def __init__(self):
self._original_compile = torch.compile

def __enter__(self):
# Turn torch.compile into a no-op
torch.compile = lambda *args, **kwargs: lambda x: x

def __exit__(self, exc_type, exc_val, exc_tb):
torch.compile = self._original_compile

0 comments on commit d33710d

Please sign in to comment.