Skip to content

Commit 79bb67a

Browse files
committed
fix moriep dispatch-floor patcher crash when sglang.__file__ is None
The vendor image installs sglang as a namespace package where __file__ is None. os.path.dirname(None) throws TypeError, so the patcher crashed and the floor was never applied — eval ran unpatched. Fall through __file__ → __path__ → importlib.util.find_spec() to locate the package directory robustly.
1 parent 6508c77 commit 79bb67a

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

benchmarks/multi_node/amd_utils/patches/apply_moriep_dispatch_floor.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,31 @@ def find_target():
4242
except Exception as e: # pragma: no cover
4343
print(f"{TAG} ERROR: could not import sglang ({e}); NOT patched")
4444
return None
45+
46+
# sglang may be a namespace package (no __init__.py) where __file__ is
47+
# None. Fall through several strategies to locate the package root.
48+
pkg_dir = None
49+
if getattr(sglang, "__file__", None) is not None:
50+
pkg_dir = os.path.dirname(sglang.__file__)
51+
elif getattr(sglang, "__path__", None):
52+
pkg_dir = list(sglang.__path__)[0]
53+
else:
54+
try:
55+
import importlib.util
56+
spec = importlib.util.find_spec("sglang")
57+
if spec and spec.submodule_search_locations:
58+
pkg_dir = list(spec.submodule_search_locations)[0]
59+
except Exception:
60+
pass
61+
62+
if pkg_dir is None:
63+
print(f"{TAG} ERROR: could not determine sglang install path "
64+
f"(__file__={getattr(sglang, '__file__', '?')}, "
65+
f"__path__={getattr(sglang, '__path__', '?')}); NOT patched")
66+
return None
67+
4568
path = os.path.join(
46-
os.path.dirname(sglang.__file__),
47-
"srt", "layers", "moe", "token_dispatcher", "moriep.py",
69+
pkg_dir, "srt", "layers", "moe", "token_dispatcher", "moriep.py",
4870
)
4971
if not os.path.isfile(path):
5072
print(f"{TAG} ERROR: moriep.py not found at {path}; NOT patched")

0 commit comments

Comments
 (0)