-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Feature] Add InstantTensor weight loader #36139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Loading Model Weights with InstantTensor | ||
|
|
||
| InstantTensor accelerates loading Safetensors weights on CUDA devices through distributed loading, pipelined prefetching, and direct I/O. InstantTensor also supports GDS (GPUDirect Storage) when available. | ||
| For more details, see the [InstantTensor GitHub repository](https://github.com/scitix/InstantTensor). | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pip install instanttensor | ||
| ``` | ||
|
|
||
| ## Use InstantTensor in vLLM | ||
|
|
||
| Add `--load-format instanttensor` as a command-line argument. | ||
|
|
||
| For example: | ||
|
|
||
| ```bash | ||
| vllm serve Qwen/Qwen2.5-0.5B --load-format instanttensor | ||
| ``` | ||
|
|
||
| ## Benchmarks | ||
|
|
||
| | Model | GPU | Backend | Load Time (s) | Throughput (GB/s) | Speedup | | ||
| | --- | ---: | --- | ---: | ---: | --- | | ||
| | Qwen3-30B-A3B | 1*H200 | Safetensors | 57.4 | 1.1 | 1x | | ||
| | Qwen3-30B-A3B | 1*H200 | InstantTensor | 1.77 | 35 | <span style="color: green">**32.4x**</span> | | ||
| | DeepSeek-R1 | 8*H200 | Safetensors | 160 | 4.3 | 1x | | ||
| | DeepSeek-R1 | 8*H200 | InstantTensor | 15.3 | 45 | <span style="color: green">**10.5x**</span> | | ||
|
|
||
| For the full benchmark results, see <https://github.com/scitix/InstantTensor/blob/main/docs/benchmark.md>. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
28 changes: 28 additions & 0 deletions
28
tests/model_executor/model_loader/instanttensor_loader/test_instanttensor_loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm import SamplingParams | ||
| from vllm.platforms import current_platform | ||
|
|
||
| test_model = "openai-community/gpt2" | ||
|
|
||
| prompts = [ | ||
| "Hello, my name is", | ||
| "The president of the United States is", | ||
| "The capital of France is", | ||
| "The future of AI is", | ||
| ] | ||
| # Create a sampling params object. | ||
| sampling_params = SamplingParams(temperature=0.8, top_p=0.95, seed=0) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not current_platform.is_cuda(), | ||
| reason="InstantTensor requires NVIDIA GPUs", | ||
| ) | ||
| def test_model_loader_download_files(vllm_runner): | ||
| with vllm_runner(test_model, load_format="instanttensor") as llm: | ||
| deserialized_outputs = llm.generate(prompts, sampling_params) | ||
| assert deserialized_outputs |
52 changes: 52 additions & 0 deletions
52
tests/model_executor/model_loader/instanttensor_loader/test_weight_utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| import glob | ||
| import tempfile | ||
|
|
||
| import huggingface_hub.constants | ||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.model_executor.model_loader.weight_utils import ( | ||
| download_weights_from_hf, | ||
| instanttensor_weights_iterator, | ||
| safetensors_weights_iterator, | ||
| ) | ||
| from vllm.platforms import current_platform | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not current_platform.is_cuda(), | ||
| reason="InstantTensor requires NVIDIA GPUs", | ||
| ) | ||
| def test_instanttensor_model_loader(): | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| huggingface_hub.constants.HF_HUB_OFFLINE = False | ||
| download_weights_from_hf( | ||
| "openai-community/gpt2", allow_patterns=["*.safetensors"], cache_dir=tmpdir | ||
| ) | ||
| safetensors = glob.glob(f"{tmpdir}/**/*.safetensors", recursive=True) | ||
| assert len(safetensors) > 0 | ||
|
|
||
| instanttensor_tensors = {} | ||
| hf_safetensors_tensors = {} | ||
|
|
||
| for name, tensor in instanttensor_weights_iterator(safetensors, True): | ||
| # Copy the tensor immediately as it is a reference to the internal | ||
| # buffer of instanttensor. | ||
| instanttensor_tensors[name] = tensor.to("cpu") | ||
|
|
||
| for name, tensor in safetensors_weights_iterator(safetensors, True): | ||
| hf_safetensors_tensors[name] = tensor | ||
|
|
||
| assert len(instanttensor_tensors) == len(hf_safetensors_tensors) | ||
|
|
||
| for name, instanttensor_tensor in instanttensor_tensors.items(): | ||
| assert instanttensor_tensor.dtype == hf_safetensors_tensors[name].dtype | ||
| assert instanttensor_tensor.shape == hf_safetensors_tensors[name].shape | ||
| assert torch.all(instanttensor_tensor.eq(hf_safetensors_tensors[name])) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_instanttensor_model_loader() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.