Skip to content

Commit

Permalink
pc
Browse files Browse the repository at this point in the history
  • Loading branch information
dakinggg committed Apr 12, 2024
1 parent c4dd2fd commit 882899a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions llmfoundry/utils/registry_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2024 MosaicML LLM Foundry authors
# SPDX-License-Identifier: Apache-2.0

import copy
import functools
import importlib.util
from contextlib import contextmanager
import os
from contextlib import contextmanager
from pathlib import Path
from types import ModuleType
from typing import (Any, Callable, Dict, Generic, Optional, Sequence, Type,
Expand Down Expand Up @@ -176,11 +177,12 @@ def import_file(loc: Union[str, Path]) -> ModuleType:
raise RuntimeError(f'Error executing {loc}') from e
return module


@contextmanager
def save_registry():
"""Save the registry state and restore after the context manager exits."""
saved_registry_state = copy.deepcopy(catalogue.REGISTRY)

yield

catalogue.REGISTRY = saved_registry_state
catalogue.REGISTRY = saved_registry_state
2 changes: 2 additions & 0 deletions tests/fixtures/autouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
REPO_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
sys.path.append(REPO_DIR)


@pytest.fixture(autouse=True)
def save_registry_fixture():
with save_registry():
yield


@pytest.fixture(autouse=True)
def initialize_dist(request: pytest.FixtureRequest):
"""Initialize the default PyTorch distributed process group for tests."""
Expand Down

0 comments on commit 882899a

Please sign in to comment.