Spaces:
Running
Running
solves import error
Browse files
scripts/training/train_gpt_oss.py
CHANGED
@@ -28,14 +28,25 @@ except Exception:
|
|
28 |
# Ensure project root and config package are importable for configs that do `from config...` imports
|
29 |
project_root = Path(__file__).resolve().parents[2]
|
30 |
if str(project_root) not in sys.path:
|
|
|
31 |
sys.path.insert(0, str(project_root))
|
32 |
config_dir = project_root / "config"
|
33 |
if str(config_dir) not in sys.path:
|
|
|
34 |
sys.path.insert(0, str(config_dir))
|
35 |
-
# Ensure 'src' is importable for modules like 'monitoring', 'model', etc
|
36 |
src_dir = project_root / "src"
|
37 |
if str(src_dir) not in sys.path:
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# Reduce tokenizer thread contention and improve CUDA allocator behavior
|
41 |
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|
|
|
28 |
# Ensure project root and config package are importable for configs that do `from config...` imports
|
29 |
project_root = Path(__file__).resolve().parents[2]
|
30 |
if str(project_root) not in sys.path:
|
31 |
+
# Put project root early so top-level packages like `config` can be resolved
|
32 |
sys.path.insert(0, str(project_root))
|
33 |
config_dir = project_root / "config"
|
34 |
if str(config_dir) not in sys.path:
|
35 |
+
# Ensure the actual `config` package takes precedence over any `config.py` module elsewhere
|
36 |
sys.path.insert(0, str(config_dir))
|
37 |
+
# Ensure 'src' is importable for modules like 'monitoring', 'model', etc., but do not shadow `config`
|
38 |
src_dir = project_root / "src"
|
39 |
if str(src_dir) not in sys.path:
|
40 |
+
# Append to the end to avoid overshadowing the `config` package with `src/config.py`
|
41 |
+
sys.path.append(str(src_dir))
|
42 |
+
|
43 |
+
# If a stray 'config' module (e.g., from src/config.py) is already imported, remove it so
|
44 |
+
# that the real package `config/` (with __init__.py) can be imported with submodules.
|
45 |
+
try:
|
46 |
+
if 'config' in sys.modules and not hasattr(sys.modules['config'], '__path__'):
|
47 |
+
del sys.modules['config']
|
48 |
+
except Exception:
|
49 |
+
pass
|
50 |
|
51 |
# Reduce tokenizer thread contention and improve CUDA allocator behavior
|
52 |
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
|