fix(sglang): support profile request object API - #11199
Conversation
This comment has been minimized.
This comment has been minimized.
WalkthroughAdds a compatibility shim in SGLang's Changesstart_profile compatibility shim
Estimated code review effort: 2 (Simple) | ~12 minutes Poem: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
components/src/dynamo/sglang/_compat.py (1)
138-149: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueBound-method unwrap + lru_cache TypeError fallback is correct but adds indirection.
Unwrapping to
__func__before calling the cached signature check (to get cross-instance cache hits) and falling back to.__wrapped__when the cache key isn't hashable are both valid uses offunctools.lru_cache, but this path only matters for the rare case of an unhashablestart_profilecallable. Consider a short comment explaining why theTypeErrorfallback exists, to save future readers from re-deriving this.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@components/src/dynamo/sglang/_compat.py` around lines 138 - 149, Add a brief inline comment near the start_profile signature check to explain why __func__ is used before the cached _start_profile_accepts_request_object call and why the TypeError fallback to __wrapped__ exists. The comment should mention that this preserves cross-instance cache hits for bound methods and only bypasses lru_cache when the callable is unhashable, so future readers understand the indirection in this _compat.py logic.components/src/dynamo/sglang/tests/test_sglang_unit.py (1)
252-252: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winHardcoded
/tmp/profileflagged by static analysis; harmless here but easy to avoid.These are just mock parameter values (never touch the filesystem), so the security implications are moot, but the literal string still trips ruff (S108) and ast-grep's hardcoded-tmp-path check across all three occurrences. Swapping to a clearly non-filesystem placeholder (e.g.,
"profile-output") keeps tests hermetic per repo guidance and silences the noise.🧹 Proposed fix
- body = {"output_dir": "/tmp/profile", "start_step": 10, "num_steps": 5} + body = {"output_dir": "profile-output", "start_step": 10, "num_steps": 5}- request = SimpleNamespace(output_dir="/tmp/profile", start_step=10, num_steps=5) + request = SimpleNamespace(output_dir="profile-output", start_step=10, num_steps=5)- {"output_dir": "/tmp/profile", "start_step": 10, "num_steps": 5}, + {"output_dir": "profile-output", "start_step": 10, "num_steps": 5},As per path instructions: "Tests must remain hermetic and parallel-safe: don't hardcode ports, temp paths, or write files into the repo tree."
Also applies to: 267-267, 275-275
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@components/src/dynamo/sglang/tests/test_sglang_unit.py` at line 252, Replace the hardcoded temporary path string used in the Sglang test payloads with a non-filesystem placeholder value so the tests stay hermetic and stop triggering S108/hardcoded tmp path checks. Update the repeated mock parameter values in test_sglang_unit.py where the request bodies are built (the occurrences around the body assignments in the relevant test cases) to use a neutral name like the profile output placeholder, keeping the same test behavior without referencing /tmp.Sources: Path instructions, Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@components/src/dynamo/sglang/_compat.py`:
- Around line 126-129: Move the ProfileReq dependency out of
_build_profile_request and import it at module scope alongside the other
top-level imports in _compat.py. This helper should just construct and return
ProfileReq(**body), with no import statement inside the function body, so the
module follows the repository import rules and makes the SGLang dependency
explicit.
---
Nitpick comments:
In `@components/src/dynamo/sglang/_compat.py`:
- Around line 138-149: Add a brief inline comment near the start_profile
signature check to explain why __func__ is used before the cached
_start_profile_accepts_request_object call and why the TypeError fallback to
__wrapped__ exists. The comment should mention that this preserves
cross-instance cache hits for bound methods and only bypasses lru_cache when the
callable is unhashable, so future readers understand the indirection in this
_compat.py logic.
In `@components/src/dynamo/sglang/tests/test_sglang_unit.py`:
- Line 252: Replace the hardcoded temporary path string used in the Sglang test
payloads with a non-filesystem placeholder value so the tests stay hermetic and
stop triggering S108/hardcoded tmp path checks. Update the repeated mock
parameter values in test_sglang_unit.py where the request bodies are built (the
occurrences around the body assignments in the relevant test cases) to use a
neutral name like the profile output placeholder, keeping the same test behavior
without referencing /tmp.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 6e7af0fc-b563-4017-8bf3-f0879eb5e513
📒 Files selected for processing (3)
components/src/dynamo/sglang/_compat.pycomponents/src/dynamo/sglang/request_handlers/handler_base.pycomponents/src/dynamo/sglang/tests/test_sglang_unit.py
|
components/src/dynamo/sglang/llm_engine.py — The unified 🤖 AI FixIn |
Signed-off-by: Po-Han Huang <pohanh@nvidia.com>
e20bb29 to
7383f19
Compare
|
/ok-to-test 7383f19 |
[by Codex]
Summary
start_profile(ProfileReq)APIValidation
python3 -m compileall -q components/src/dynamo/sglang/_compat.py components/src/dynamo/sglang/request_handlers/handler_base.py components/src/dynamo/sglang/tests/test_sglang_unit.pygit diff --check5b76f55d:/engine/start_profilereturnedTypeError: TokenizerControlMixin.start_profile() got an unexpected keyword argument output_dirbeforecudaProfilerStartThe focused pytest cases were added but not run locally because this VM does not have the Dynamo/SGLang test environment installed.
Overview:
Newer SGLang builds changed
TokenizerManager.start_profilefrom individual keyword arguments to a singleProfileReq. Dynamo still unpacked the HTTP body as kwargs, causing every profiling request to fail with HTTP 500.Details:
start_profile_compatinspects the installed method signature. It preserves kwargs for SGLang 0.5.11 and constructsProfileReq(**body)for current builds.Where should the reviewer start?
components/src/dynamo/sglang/_compat.pyRelated Issues
This PR is NOT linked to an issue:
Summary by CodeRabbit
Bug Fixes
Tests