Refactor: move model provisioning policies to streamwise/model_provisioner/#312
Refactor: move model provisioning policies to streamwise/model_provisioner/#312James-QiuHaoran wants to merge 3 commits into
Conversation
…ioner/ Move the 6 policy/allocator files (greedy, milp, naive_baseline, hexgen, helix, policies) from simulator/ into streamwise/model_provisioner/ so they can be reused by both the simulator evaluation framework and the StreamWise serving system. - Create streamwise/model_provisioner/ package with __init__.py that adds simulator/ to sys.path for foundation module access - Create simulator/__init__.py that adds streamwise/ to sys.path so model_provisioner is importable from simulator code - Update all imports across simulator files and 20 test files - Switch data_loading.py to use Path instead of str for data_dir params - Fix mypy issue in wrapper/run_httpserver.py (bytearray assignment) - Add .venv to .flake8 exclude and .gitignore Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kdh0102
left a comment
There was a problem hiding this comment.
Overall, looks good to me.
I still encounter some path issues in the jupyter notebooks, and I handled the cases by adding another block:
import pathlib
import sys
streamwise_path = pathlib.Path().resolve().parent / "streamwise"
if str(streamwise_path) not in sys.path:
sys.path.insert(0, str(streamwise_path))
If you don't think this fix needs to be handled in this PR, it looks good for me to merge.
Support both local dev (../../simulator) and Docker (../simulator) paths when resolving the simulator directory for foundation module imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the 6 model provisioning policy/allocator files (policies, greedy, milp, naive_baseline, hexgen, helix) out of simulator/ and into a new streamwise/model_provisioner/ package so the same code can be reused by both the simulator evaluation framework and the StreamWise serving system. Cross-package imports are enabled via sys.path injection in two new __init__.py files. Tests are updated to extend temp_sys_path and use the new dotted module paths.
Changes:
- Create
streamwise/model_provisioner/package containing the moved allocator/policy modules with intra-package relative imports. - Add
simulator/__init__.pyandstreamwise/model_provisioner/__init__.pythat mutatesys.pathto bridge the two packages. - Update all simulator-source and ~20 test-file imports; switch
data_loading.pydefaults to aPath-resolved absolute data dir; small mypy fix inwrapper/run_httpserver.py; ignore.venvin.flake8/.gitignore.
Reviewed changes
Copilot reviewed 35 out of 37 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| streamwise/model_provisioner/init.py | New package init; injects simulator/ into sys.path to satisfy foundation imports. |
| streamwise/model_provisioner/policies.py | Moved policy definitions; uses absolute imports from simulator/. |
| streamwise/model_provisioner/greedy.py | Moved; switched to relative imports for sibling policies module. |
| streamwise/model_provisioner/milp.py | Moved; relative import of .policies. |
| streamwise/model_provisioner/naive_baseline.py | Moved; relative imports of .policies. |
| streamwise/model_provisioner/hexgen.py | Moved; relative imports of .greedy/.policies. |
| streamwise/model_provisioner/helix.py | Moved; relative imports of .milp/.policies. |
| simulator/init.py | New package init; injects streamwise/ into sys.path. |
| simulator/auto_model_allocator.py | Update lazy imports to model_provisioner.*. |
| simulator/actions.py, multirequests.py, provisioning.py, model_allocator.py | Update policy imports to model_provisioner.policies. |
| simulator/data_loading.py | Default data_dir switched to absolute Path of simulator/data/; accepts str | Path. |
| wrapper/run_httpserver.py | Rename payload_bytes rebinding to payload_buffer to satisfy mypy. |
| tests/simulator/test_*.py (16 files) | Add "streamwise" to temp_sys_path and update imports to model_provisioner.*. |
| .flake8, .gitignore | Exclude .venv. |
| _STREAMWISE_DIR = os.path.normpath( | ||
| os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "streamwise") | ||
| ) | ||
| if _STREAMWISE_DIR not in sys.path: | ||
| sys.path.insert(0, _STREAMWISE_DIR) |
| # Add simulator/ to sys.path so policy files can import foundation modules. | ||
| # Supports both local dev layout (../../simulator) and Docker layout (../simulator). | ||
| _HERE = os.path.dirname(os.path.abspath(__file__)) | ||
| _CANDIDATES = [ | ||
| os.path.normpath(os.path.join(_HERE, "..", "..", "simulator")), | ||
| os.path.normpath(os.path.join(_HERE, "..", "simulator")), | ||
| ] | ||
| for _path in _CANDIDATES: | ||
| if os.path.isdir(_path) and _path not in sys.path: | ||
| sys.path.insert(0, _path) | ||
| break |
Agent-Logs-Url: https://github.com/Azure/realtimevideogen/sessions/d53596b3-c563-4deb-af27-7226e9dac364 Co-authored-by: James-QiuHaoran <22564180+James-QiuHaoran@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Lint Results
|
Mypy Type Checking✅ No issues found
Full mypy output |
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
simulator/init.pyLines 3-16 3 on top of the model_provisioner allocation policies.
4
5 The allocation policy implementations live in ``streamwise/model_provisioner/``.
6 """
! 7 import os
! 8 import sys
9
10 # Make model_provisioner importable for simulator modules.
! 11 _STREAMWISE_DIR = os.path.normpath(
12 os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "streamwise")
13 )
! 14 if _STREAMWISE_DIR not in sys.path:
! 15 sys.path.insert(0, _STREAMWISE_DIR)wrapper/run_httpserver.pyLines 1265-1274 1265 last_ping_time = time.time()
1266
1267 try:
1268 payload_bytes = await asyncio.to_thread(pickle.dumps, gen_task)
! 1269 payload_buffer = bytearray(payload_bytes)
! 1270 payload_tensor = torch.frombuffer(payload_buffer, dtype=torch.uint8).to("cuda")
1271 payload_size = torch.tensor([payload_tensor.numel()], dtype=torch.int64, device="cuda")
1272
1273 if payload_size.item() > MAX_PAYLOAD_BYTES:
1274 logging.error(f"[{rank}] Payload too large: {payload_size.item()} bytes.") |
|
Move the 6 policy/allocator files (greedy, milp, naive_baseline, hexgen, helix, policies) from
simulator/intostreamwise/model_provisioner/so they can be reused by both the simulator evaluation framework and the StreamWise serving system.Changes
streamwise/model_provisioner/package with__init__.pythat addssimulator/tosys.pathfor foundation module accesssimulator/__init__.pythat addsstreamwise/tosys.pathsomodel_provisioneris importable from simulator codedata_loading.pyto usePathinstead ofstrfordata_dirparams (accepts bothstr | Path)wrapper/run_httpserver.py(bytearray assignment).venvto.flake8exclude and.gitignoreTesting