Repository navigation
feat: stream S3 safetensors with Run:ai Model Streamer 0.17.0 - #5241
Reinerzhou wants to merge 5 commits into
Conversation
e6b5438 to
e2388a4
Compare
c055331 to
96e0851
Compare
25e03a5 to
ea1aeca
Compare
| os.getenv('RUNAI_STREAMER_MEMORY_LIMIT', 'default')) | ||
| with SafetensorsStreamer() as streamer: | ||
| try: | ||
| streamer.stream_files(files, |
There was a problem hiding this comment.
With target TP > 1 and a non-DeepSeek EAGLE3 draft on S3, build_spec_agent() creates a proposer only on the TP leader; follower ranks skip draft loading. Run:ai 0.17.0 performs global rank-discovery collectives even with is_distributed=False, so this call waits for ranks that never participate and startup times out. A two-process CPU/Gloo check reproduced the timeout, while loading on both ranks succeeded. Reject this configuration before worker startup or arrange collective participation; documenting the upstream limitation does not prevent this existing speculative-decoding path from encountering it.
silencelamb
left a comment
There was a problem hiding this comment.
Reviewed ea1aeca with the official Run:ai 0.17.0 wheels. All 19 tests in the two new weight-loader test files passed locally. I recommend fixing the cache identity and S3 endpoint handling before merging.
| cache_root = download_dir or os.getenv('LMDEPLOY_RUNAI_CACHE_DIR') or os.path.join(tempfile.gettempdir(), | ||
| 'lmdeploy_runai') | ||
| os.makedirs(cache_root, exist_ok=True) | ||
| model_dir = os.path.join(cache_root, hashlib.sha256(model_uri.encode()).hexdigest()) |
There was a problem hiding this comment.
[P1] Include the effective S3 endpoint in the metadata cache key. Two independent S3 endpoints can serve different checkpoints at the same bucket and prefix. I loaded the same URI through two local S3 endpoints with a shared cache using the official 0.17.0 wheels. The second load reused endpoint A's config.json and streamed endpoint B's tensors. This can pair the wrong configuration or tokenizer with otherwise loadable weights. Resolve one effective S3 endpoint for both readers and include it alongside the URI in the cache key.
| env['RUNAI_STREAMER_S3_ENDPOINT'] = env['AWS_ENDPOINT_URL'] | ||
| if 'AWS_ENDPOINT_URL' not in env and 'RUNAI_STREAMER_S3_ENDPOINT' in env: | ||
| # Run:ai 0.17.0 pull_files uses boto3, which reads AWS_ENDPOINT_URL. | ||
| env['AWS_ENDPOINT_URL'] = env['RUNAI_STREAMER_S3_ENDPOINT'] |
There was a problem hiding this comment.
[P2] Scope the custom endpoint to S3. Setting RUNAI_STREAMER_S3_ENDPOINT also sets AWS_ENDPOINT_URL, which botocore honors for other services. I verified that a newly constructed STS client is redirected to the S3 endpoint. This can break AssumeRole credential resolution when the custom endpoint only serves S3. Use an S3-specific endpoint such as AWS_ENDPOINT_URL_S3 for the metadata client and pass it to Ray workers where needed.
| with open(os.path.join(staging, _RUNAI_SOURCE_FILE), 'w', encoding='utf-8') as f: | ||
| json.dump({'model_uri': model_uri}, f) | ||
| os.rename(staging, model_dir) | ||
| return model_dir |
There was a problem hiding this comment.
[P2] Preserve the source model name for chat-template selection. get_chat_template() uses the model path for built-in name matches. I loaded identical Vicuna metadata and a tokenizer without a chat template from a named local directory and from this S3 cache. The local path selected Vicuna, while the hash-only path fell back to BaseChatTemplate and removed the user and assistant prompt delimiters. Use the original model name for matching and the metadata cache path for tokenizer loading.
|
|
||
| if extra_config is not None: | ||
| env['LMDEPLOY_RUNAI_DISTRIBUTED'] = str(distributed).lower() | ||
| if concurrency is not None: |
There was a problem hiding this comment.
[P2] Scope loader overrides to the engine that supplied them. concurrency and memory_limit are written to os.environ and are left in place when a later engine omits them. I confirmed that applying explicit overrides and then applying an empty configuration retains both values. In a process hosting more than one Python pipeline, starting a second pipeline with defaults can therefore reuse the first pipeline's S3 tuning. Carry the resolved settings with the engine to the worker that opens the streamer.
| else get_max_batch_size(args.device) | ||
| backend = args.backend | ||
| is_s3_model = is_runai_model(args.model_path) | ||
| if args.load_format == 'runai_streamer' and not is_s3_model: |
There was a problem hiding this comment.
[P2] Validate the load format and backend before downloading. The CLI entry point resolves args.model_path with get_model() before reaching this check. I intercepted get_model() for lmdeploy serve api_server org/model --load-format runai_streamer and confirmed it is called first. With an uncached Hugging Face repo, this can download the entire checkpoint before rejecting the command. Validate the option combination against the original input before model resolution.
|
|
||
| def is_runai_model(model_path: str) -> bool: | ||
| """Return whether a path is an S3 URI or its metadata cache.""" | ||
| return model_path.startswith('s3://') or get_runai_model_uri(model_path) is not None |
There was a problem hiding this comment.
[P3] Preserve local pathlib.Path compatibility. autoget_backend_config(Path(...)) selects the backend at the base revision and raises AttributeError at this line on the PR head. Normalize path-like inputs before applying the S3 prefix check.
| eager_mode: bool = False | ||
| custom_module_map: dict[str, str] = None | ||
| download_dir: str = None | ||
| model_loader_extra_config: dict[str, Any] | None = None |
There was a problem hiding this comment.
[P3] Preserve the public config's positional argument order. Inserting this field before revision shifts the existing constructor arguments. I verified that an argument passed in the old revision slot is stored in model_loader_extra_config and leaves revision=None. Make the new field keyword-only or append it after the existing fields.
ea1aeca to
bd3429b
Compare
bd3429b to
0b7d1f7
Compare
Summary
runai-model-streamer==0.17.0andrunai-model-streamer-s3==0.17.0wheels.requirements/serve.txtlists their S3 dependency chain for serving images that install LMDeploy withpip --no-deps, includingpython-dateutil>=2.1,<3.0.0to satisfy botocore; the existingrequirements_cuda.txtincludesserve.txt, so the CUDAallextra also includes it. PyTorch remains in LMDeploy's CUDA runtime dependencies.model.safetensors.index.jsonwithout a separate weight listing during streaming. Existing MTP drafts select only their own tensors and shards; local and S3 loading share this selection rule. Unindexed checkpoints read only rootmodel.safetensors.--load-format runai_streamer,--model-loader-extra-config, andPytorchEngineConfig.model_loader_extra_config. Loader overrides are passed through engine configuration and restored after each stream. Ray workers receive non-secret S3 settings and reconstruct metadata in their cache directory. Custom endpoints useAWS_ENDPOINT_URL_S3for boto3 metadata requests, leaving STS unchanged.Validation
With the official Run:ai 0.17.0 wheels, pre-commit and the relevant local weight-loader/MemDecode tests passed 36/36 on
79f382d1. Current-head CI passed: lint, unit tests, PR function tests, and Chinese documentation.Real S3 GLM-5.3-Flash serving was rerun on current head
79f382d1, one H200 node, TP4,memory_limit=0. Each configuration passed/health, chat, and the same 64-question GSM8K subset (temperature=1.0,max_tokens=10240). All 64 requests succeeded without errors in every run. Startup is time to health, not a controlled performance benchmark.distributedconcurrencyfalsefalsefalsetruetruetrueAll scores exceeded 95% on this subset. The final run answered one fewer question correctly than the earlier run; sampling used
temperature=1.0.On the current code, a local Llama-3.1-8B-Instruct target with an independent EAGLE3 draft on test-only MinIO S3 started at TP1, returned HTTP 200, and produced 59 output tokens; metrics recorded 15 draft proposals and 45 accepted draft tokens. The publicly available draft was distributed as
.bin, so its tensors were converted to safetensors for this test only. The unsupported target-TP2/draft-TP1 case returned the intendedValueErrordirectly, before engine spawn. On MinIO, replacingconfig.jsonat the same S3 URI selected a new metadata cache while preserving the old cache; an anonymous public S3 cache hit also succeeded without downloading weights. On current head79f382d1, public S3 Qwen3-1.7B at TP2 (distributed=false,concurrency=4) also passed health and Chat Completions; the request finished with the correct answer. Multi-node serving and controlled comparative startup performance remain unverified.Scope and known limits
owned=Truein both modes.distributed=falsestreams each rank to CPU;distributed=trueuses Run:ai CUDA rank sharing and preserves identical shard order across ranks.concurrency=1condition. This PR rejects the identified independent-S3-draft/target-TP>1 case before worker startup. A follow-up can move to a later official 0.17.x release after approval and compatibility tests.