add precommit
This commit is contained in:
1 parent
1bf3424e96
commit
a04e945166
19 files changed
+265
-208
No files matched your search
@@ -0,0 +1,44 @@
|
|||||||
|
# Set default behavior to automatically normalize line endings
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Explicitly declare text files you want to always be normalized and converted
|
||||||
|
# to native line endings on checkout
|
||||||
|
*.py text eol=lf
|
||||||
|
*.yaml text eol=lf
|
||||||
|
*.yml text eol=lf
|
||||||
|
*.md text eol=lf
|
||||||
|
*.txt text eol=lf
|
||||||
|
*.json text eol=lf
|
||||||
|
*.toml text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
|
||||||
|
# Declare files that will always have CRLF line endings on checkout
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
|
||||||
|
# Denote all files that are truly binary and should not be modified
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.gif binary
|
||||||
|
*.ico binary
|
||||||
|
*.mov binary
|
||||||
|
*.mp4 binary
|
||||||
|
*.mp3 binary
|
||||||
|
*.flv binary
|
||||||
|
*.fla binary
|
||||||
|
*.swf binary
|
||||||
|
*.gz binary
|
||||||
|
*.zip binary
|
||||||
|
*.7z binary
|
||||||
|
*.ttf binary
|
||||||
|
*.eot binary
|
||||||
|
*.woff binary
|
||||||
|
*.woff2 binary
|
||||||
|
*.pyc binary
|
||||||
|
*.pdf binary
|
||||||
|
*.ai binary
|
||||||
|
*.psd binary
|
||||||
|
*.xcf binary
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.3.0
|
||||||
|
hooks:
|
||||||
|
# list of supported hooks: https://pre-commit.com/hooks.html
|
||||||
|
- id: check-yaml
|
||||||
|
args: ["--unsafe"]
|
||||||
|
- id: debug-statements
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: mixed-line-ending
|
||||||
|
args: ["--fix=lf"]
|
||||||
|
- id: trailing-whitespace
|
||||||
|
args: ["--markdown-linebreak-ext=md"]
|
||||||
|
|
||||||
|
- repo: https://github.com/PyCQA/isort
|
||||||
|
rev: 5.11.5
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.1.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: 4.0.1
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
args: ["--max-line-length=88", "--extend-ignore=E203,W503"]
|
||||||
@@ -6,9 +6,9 @@ This example shows how to interact with the vLLM-omni API server
|
|||||||
using HTTP requests.
|
using HTTP requests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import time
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def test_health(host="localhost", port=8000):
|
def test_health(host="localhost", port=8000):
|
||||||
@@ -70,7 +70,7 @@ def main():
|
|||||||
result = generate_text("Hello, how are you?", max_tokens=50)
|
result = generate_text("Hello, how are you?", max_tokens=50)
|
||||||
if result:
|
if result:
|
||||||
text = result["outputs"][0]["text"]
|
text = result["outputs"][0]["text"]
|
||||||
print(f" Input: Hello, how are you?")
|
print(" Input: Hello, how are you?")
|
||||||
print(f" Output: {text}")
|
print(f" Output: {text}")
|
||||||
|
|
||||||
# Example 2: Creative writing
|
# Example 2: Creative writing
|
||||||
@@ -78,32 +78,26 @@ def main():
|
|||||||
result = generate_text(
|
result = generate_text(
|
||||||
"Write a short story about a robot learning to paint",
|
"Write a short story about a robot learning to paint",
|
||||||
max_tokens=150,
|
max_tokens=150,
|
||||||
temperature=0.9
|
temperature=0.9,
|
||||||
)
|
)
|
||||||
if result:
|
if result:
|
||||||
text = result["outputs"][0]["text"]
|
text = result["outputs"][0]["text"]
|
||||||
print(f" Input: Write a short story about a robot learning to paint")
|
print(" Input: Write a short story about a robot learning to paint")
|
||||||
print(f" Output: {text}")
|
print(f" Output: {text}")
|
||||||
|
|
||||||
# Example 3: Question answering
|
# Example 3: Question answering
|
||||||
print("\n3. Question answering:")
|
print("\n3. Question answering:")
|
||||||
result = generate_text(
|
result = generate_text(
|
||||||
"What is the capital of France?",
|
"What is the capital of France?", max_tokens=30, temperature=0.3
|
||||||
max_tokens=30,
|
|
||||||
temperature=0.3
|
|
||||||
)
|
)
|
||||||
if result:
|
if result:
|
||||||
text = result["outputs"][0]["text"]
|
text = result["outputs"][0]["text"]
|
||||||
print(f" Input: What is the capital of France?")
|
print(" Input: What is the capital of France?")
|
||||||
print(f" Output: {text}")
|
print(f" Output: {text}")
|
||||||
|
|
||||||
# Example 4: Multiple prompts
|
# Example 4: Multiple prompts
|
||||||
print("\n4. Multiple prompts:")
|
print("\n4. Multiple prompts:")
|
||||||
prompts = [
|
prompts = ["Tell me a joke", "What's 2+2?", "Describe the color blue"]
|
||||||
"Tell me a joke",
|
|
||||||
"What's 2+2?",
|
|
||||||
"Describe the color blue"
|
|
||||||
]
|
|
||||||
|
|
||||||
for prompt in prompts:
|
for prompt in prompts:
|
||||||
result = generate_text(prompt, max_tokens=30)
|
result = generate_text(prompt, max_tokens=30)
|
||||||
@@ -125,4 +119,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
@@ -7,8 +7,9 @@ with a single AR (Autoregressive) stage.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from vllm_omni.entrypoints.omni_llm import OmniLLM, AsyncOmniLLM
|
|
||||||
from vllm_omni.config import create_ar_stage_config
|
from vllm_omni.config import create_ar_stage_config
|
||||||
|
from vllm_omni.entrypoints.omni_llm import AsyncOmniLLM, OmniLLM
|
||||||
|
|
||||||
|
|
||||||
def sync_example():
|
def sync_example():
|
||||||
@@ -20,18 +21,20 @@ def sync_example():
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path="Qwen/Qwen3-0.6B",
|
model_path="Qwen/Qwen3-0.6B",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize OmniLLM
|
# Initialize OmniLLM
|
||||||
omni_llm = OmniLLM([stage_config])
|
omni_llm = OmniLLM([stage_config])
|
||||||
|
|
||||||
# Prepare stage arguments
|
# Prepare stage arguments
|
||||||
stage_args = [{
|
stage_args = [
|
||||||
"prompt": "Hello, how are you today?",
|
{
|
||||||
"max_tokens": 50,
|
"prompt": "Hello, how are you today?",
|
||||||
"temperature": 0.7
|
"max_tokens": 50,
|
||||||
}]
|
"temperature": 0.7,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
# Generate text
|
# Generate text
|
||||||
print(f"Input: {stage_args[0]['prompt']}")
|
print(f"Input: {stage_args[0]['prompt']}")
|
||||||
@@ -40,7 +43,7 @@ def sync_example():
|
|||||||
# Display results
|
# Display results
|
||||||
for i, output in enumerate(outputs):
|
for i, output in enumerate(outputs):
|
||||||
print(f"Output {i}:")
|
print(f"Output {i}:")
|
||||||
if hasattr(output, 'outputs') and output.outputs:
|
if hasattr(output, "outputs") and output.outputs:
|
||||||
for completion in output.outputs:
|
for completion in output.outputs:
|
||||||
print(f" Text: {completion.text}")
|
print(f" Text: {completion.text}")
|
||||||
print(f" Finished: {completion.finish_reason != 'length'}")
|
print(f" Finished: {completion.finish_reason != 'length'}")
|
||||||
@@ -56,18 +59,20 @@ async def async_example():
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path="Qwen/Qwen3-0.6B",
|
model_path="Qwen/Qwen3-0.6B",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize AsyncOmniLLM
|
# Initialize AsyncOmniLLM
|
||||||
omni_llm = AsyncOmniLLM([stage_config])
|
omni_llm = AsyncOmniLLM([stage_config])
|
||||||
|
|
||||||
# Prepare stage arguments
|
# Prepare stage arguments
|
||||||
stage_args = [{
|
stage_args = [
|
||||||
"prompt": "What is artificial intelligence?",
|
{
|
||||||
"max_tokens": 100,
|
"prompt": "What is artificial intelligence?",
|
||||||
"temperature": 0.8
|
"max_tokens": 100,
|
||||||
}]
|
"temperature": 0.8,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
# Generate text asynchronously
|
# Generate text asynchronously
|
||||||
print(f"Input: {stage_args[0]['prompt']}")
|
print(f"Input: {stage_args[0]['prompt']}")
|
||||||
@@ -76,7 +81,7 @@ async def async_example():
|
|||||||
# Display results
|
# Display results
|
||||||
for i, output in enumerate(outputs):
|
for i, output in enumerate(outputs):
|
||||||
print(f"Output {i}:")
|
print(f"Output {i}:")
|
||||||
if hasattr(output, 'outputs') and output.outputs:
|
if hasattr(output, "outputs") and output.outputs:
|
||||||
for completion in output.outputs:
|
for completion in output.outputs:
|
||||||
print(f" Text: {completion.text}")
|
print(f" Text: {completion.text}")
|
||||||
print(f" Finished: {completion.finish_reason != 'length'}")
|
print(f" Finished: {completion.finish_reason != 'length'}")
|
||||||
@@ -92,7 +97,7 @@ def multi_prompt_example():
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path="Qwen/Qwen3-0.6B",
|
model_path="Qwen/Qwen3-0.6B",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialize OmniLLM
|
# Initialize OmniLLM
|
||||||
@@ -102,20 +107,16 @@ def multi_prompt_example():
|
|||||||
prompts = [
|
prompts = [
|
||||||
"Tell me a joke",
|
"Tell me a joke",
|
||||||
"What's the weather like?",
|
"What's the weather like?",
|
||||||
"Explain quantum computing"
|
"Explain quantum computing",
|
||||||
]
|
]
|
||||||
|
|
||||||
for prompt in prompts:
|
for prompt in prompts:
|
||||||
print(f"\nInput: {prompt}")
|
print(f"\nInput: {prompt}")
|
||||||
stage_args = [{
|
stage_args = [{"prompt": prompt, "max_tokens": 30, "temperature": 0.9}]
|
||||||
"prompt": prompt,
|
|
||||||
"max_tokens": 30,
|
|
||||||
"temperature": 0.9
|
|
||||||
}]
|
|
||||||
|
|
||||||
outputs = omni_llm.generate(stage_args)
|
outputs = omni_llm.generate(stage_args)
|
||||||
|
|
||||||
if outputs and hasattr(outputs[0], 'outputs') and outputs[0].outputs:
|
if outputs and hasattr(outputs[0], "outputs") and outputs[0].outputs:
|
||||||
completion = outputs[0].outputs[0]
|
completion = outputs[0].outputs[0]
|
||||||
print(f"Output: {completion.text}")
|
print(f"Output: {completion.text}")
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ from typing import Dict, List
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from vllm_omni import (
|
from vllm_omni import (
|
||||||
OmniLLM,
|
|
||||||
DiTConfig,
|
DiTConfig,
|
||||||
|
OmniLLM,
|
||||||
create_ar_stage_config,
|
create_ar_stage_config,
|
||||||
create_dit_stage_config,
|
create_dit_stage_config,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ multi_line_output = 3
|
|||||||
line_length = 88
|
line_length = 88
|
||||||
known_first_party = ["vllm_omni"]
|
known_first_party = ["vllm_omni"]
|
||||||
|
|
||||||
|
[tool.flake8]
|
||||||
|
max-line-length = 88
|
||||||
|
extend-ignore = ["E203", "W503"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.8"
|
python_version = "3.8"
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
|
|||||||
@@ -106,4 +106,3 @@ python scripts/download_models.py
|
|||||||
- `server.log`: Server startup and runtime logs
|
- `server.log`: Server startup and runtime logs
|
||||||
- `api_client_test.log`: API client test results
|
- `api_client_test.log`: API client test results
|
||||||
- `simple_usage_test.log`: Simple usage test results
|
- `simple_usage_test.log`: Simple usage test results
|
||||||
|
|
||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
Test suite for vLLM-omni.
|
Test suite for vLLM-omni.
|
||||||
|
|
||||||
This package contains unit tests, integration tests, and benchmarks for vLLM-omni.
|
This package contains unit tests, integration tests, and benchmarks
|
||||||
|
for vLLM-omni.
|
||||||
"""
|
"""
|
||||||
+14
-10
@@ -2,10 +2,17 @@
|
|||||||
Shared fixtures and configuration for vLLM-omni tests.
|
Shared fixtures and configuration for vLLM-omni tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
from unittest.mock import Mock
|
|
||||||
from vllm_omni.config import OmniStageConfig, DiTConfig, DiTCacheConfig, create_ar_stage_config, create_dit_stage_config
|
from vllm_omni.config import (
|
||||||
|
DiTCacheConfig,
|
||||||
|
DiTConfig,
|
||||||
|
create_ar_stage_config,
|
||||||
|
create_dit_stage_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
@@ -21,7 +28,7 @@ def sample_ar_stage_config():
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path="test-ar-model",
|
model_path="test-ar-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +39,7 @@ def sample_dit_stage_config():
|
|||||||
model_type="dit",
|
model_type="dit",
|
||||||
scheduler_type="ddpm",
|
scheduler_type="ddpm",
|
||||||
num_inference_steps=10,
|
num_inference_steps=10,
|
||||||
guidance_scale=7.5
|
guidance_scale=7.5,
|
||||||
)
|
)
|
||||||
|
|
||||||
return create_dit_stage_config(
|
return create_dit_stage_config(
|
||||||
@@ -40,7 +47,7 @@ def sample_dit_stage_config():
|
|||||||
model_path="test-dit-model",
|
model_path="test-dit-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["image"],
|
output_modalities=["image"],
|
||||||
dit_config=dit_config
|
dit_config=dit_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -67,10 +74,7 @@ def mock_dit_cache_config():
|
|||||||
|
|
||||||
cache_tensors = [
|
cache_tensors = [
|
||||||
DiTCacheTensor(
|
DiTCacheTensor(
|
||||||
name="test_tensor",
|
name="test_tensor", shape=[1, 512, 512], dtype="float32", persistent=True
|
||||||
shape=[1, 512, 512],
|
|
||||||
dtype="float32",
|
|
||||||
persistent=True
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -78,5 +82,5 @@ def mock_dit_cache_config():
|
|||||||
cache_tensors=cache_tensors,
|
cache_tensors=cache_tensors,
|
||||||
max_cache_size=1024 * 1024 * 1024, # 1GB
|
max_cache_size=1024 * 1024 * 1024, # 1GB
|
||||||
cache_strategy="fifo",
|
cache_strategy="fifo",
|
||||||
enable_optimization=True
|
enable_optimization=True,
|
||||||
)
|
)
|
||||||
+18
-37
@@ -3,11 +3,12 @@ Unit tests for configuration modules.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from vllm_omni.config import (
|
from vllm_omni.config import (
|
||||||
OmniStageConfig,
|
|
||||||
DiTConfig,
|
|
||||||
DiTCacheConfig,
|
DiTCacheConfig,
|
||||||
DiTCacheTensor,
|
DiTCacheTensor,
|
||||||
|
DiTConfig,
|
||||||
|
OmniStageConfig,
|
||||||
create_ar_stage_config,
|
create_ar_stage_config,
|
||||||
create_dit_stage_config,
|
create_dit_stage_config,
|
||||||
)
|
)
|
||||||
@@ -21,7 +22,7 @@ class TestOmniStageConfig:
|
|||||||
engine_type="AR",
|
engine_type="AR",
|
||||||
model_path="test-model",
|
model_path="test-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
assert config.engine_type == "AR"
|
assert config.engine_type == "AR"
|
||||||
assert config.stage_id == 0
|
assert config.stage_id == 0
|
||||||
@@ -31,22 +32,18 @@ class TestOmniStageConfig:
|
|||||||
|
|
||||||
def test_dit_stage_config_creation(self):
|
def test_dit_stage_config_creation(self):
|
||||||
"""Test DiT stage configuration creation."""
|
"""Test DiT stage configuration creation."""
|
||||||
dit_config = DiTConfig(
|
dit_config = DiTConfig(num_inference_steps=50)
|
||||||
model_type="dit",
|
|
||||||
scheduler_type="ddpm",
|
|
||||||
num_inference_steps=50
|
|
||||||
)
|
|
||||||
config = OmniStageConfig(
|
config = OmniStageConfig(
|
||||||
stage_id=1,
|
stage_id=1,
|
||||||
engine_type="DiT",
|
engine_type="DiT",
|
||||||
model_path="test-dit-model",
|
model_path="test-dit-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["image"],
|
output_modalities=["image"],
|
||||||
dit_config=dit_config
|
dit_config=dit_config,
|
||||||
)
|
)
|
||||||
assert config.engine_type == "DiT"
|
assert config.engine_type == "DiT"
|
||||||
assert config.dit_config is not None
|
assert config.dit_config is not None
|
||||||
assert config.dit_config.model_type == "dit"
|
assert config.dit_config.num_inference_steps == 50
|
||||||
|
|
||||||
def test_invalid_engine_type(self):
|
def test_invalid_engine_type(self):
|
||||||
"""Test validation of engine type."""
|
"""Test validation of engine type."""
|
||||||
@@ -56,7 +53,7 @@ class TestOmniStageConfig:
|
|||||||
engine_type="INVALID",
|
engine_type="INVALID",
|
||||||
model_path="test-model",
|
model_path="test-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_empty_modalities(self):
|
def test_empty_modalities(self):
|
||||||
@@ -67,7 +64,7 @@ class TestOmniStageConfig:
|
|||||||
engine_type="AR",
|
engine_type="AR",
|
||||||
model_path="test-model",
|
model_path="test-model",
|
||||||
input_modalities=[],
|
input_modalities=[],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
@@ -76,7 +73,7 @@ class TestOmniStageConfig:
|
|||||||
engine_type="AR",
|
engine_type="AR",
|
||||||
model_path="test-model",
|
model_path="test-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=[]
|
output_modalities=[],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_dit_requires_config(self):
|
def test_dit_requires_config(self):
|
||||||
@@ -87,18 +84,14 @@ class TestOmniStageConfig:
|
|||||||
engine_type="DiT",
|
engine_type="DiT",
|
||||||
model_path="test-dit-model",
|
model_path="test-dit-model",
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["image"]
|
output_modalities=["image"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestDiTConfig:
|
class TestDiTConfig:
|
||||||
def test_dit_config_defaults(self):
|
def test_dit_config_defaults(self):
|
||||||
"""Test DiT configuration with defaults."""
|
"""Test DiT configuration with defaults."""
|
||||||
config = DiTConfig(
|
config = DiTConfig(num_inference_steps=50)
|
||||||
model_type="dit",
|
|
||||||
scheduler_type="ddpm",
|
|
||||||
num_inference_steps=50
|
|
||||||
)
|
|
||||||
assert config.use_diffusers is False
|
assert config.use_diffusers is False
|
||||||
assert config.diffusers_pipeline is None
|
assert config.diffusers_pipeline is None
|
||||||
assert config.guidance_scale == 7.5
|
assert config.guidance_scale == 7.5
|
||||||
@@ -108,11 +101,9 @@ class TestDiTConfig:
|
|||||||
def test_diffusers_config(self):
|
def test_diffusers_config(self):
|
||||||
"""Test DiT configuration with diffusers."""
|
"""Test DiT configuration with diffusers."""
|
||||||
config = DiTConfig(
|
config = DiTConfig(
|
||||||
model_type="dit",
|
|
||||||
scheduler_type="ddpm",
|
|
||||||
num_inference_steps=50,
|
num_inference_steps=50,
|
||||||
use_diffusers=True,
|
use_diffusers=True,
|
||||||
diffusers_pipeline="stable-diffusion"
|
diffusers_pipeline="stable-diffusion",
|
||||||
)
|
)
|
||||||
assert config.use_diffusers is True
|
assert config.use_diffusers is True
|
||||||
assert config.diffusers_pipeline == "stable-diffusion"
|
assert config.diffusers_pipeline == "stable-diffusion"
|
||||||
@@ -126,14 +117,14 @@ class TestDiTCacheConfig:
|
|||||||
name="test_tensor",
|
name="test_tensor",
|
||||||
shape=[1, 512, 512],
|
shape=[1, 512, 512],
|
||||||
dtype="float32",
|
dtype="float32",
|
||||||
persistent=True
|
persistent=True,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
config = DiTCacheConfig(
|
config = DiTCacheConfig(
|
||||||
cache_tensors=cache_tensors,
|
cache_tensors=cache_tensors,
|
||||||
max_cache_size=1024 * 1024 * 1024,
|
max_cache_size=1024 * 1024 * 1024,
|
||||||
cache_strategy="fifo"
|
cache_strategy="fifo",
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(config.cache_tensors) == 1
|
assert len(config.cache_tensors) == 1
|
||||||
@@ -145,10 +136,7 @@ class TestDiTCacheConfig:
|
|||||||
class TestHelperFunctions:
|
class TestHelperFunctions:
|
||||||
def test_create_ar_stage_config(self):
|
def test_create_ar_stage_config(self):
|
||||||
"""Test create_ar_stage_config helper function."""
|
"""Test create_ar_stage_config helper function."""
|
||||||
config = create_ar_stage_config(
|
config = create_ar_stage_config(stage_id=0, model_path="test-model")
|
||||||
stage_id=0,
|
|
||||||
model_path="test-model"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert config.stage_id == 0
|
assert config.stage_id == 0
|
||||||
assert config.engine_type == "AR"
|
assert config.engine_type == "AR"
|
||||||
@@ -158,16 +146,10 @@ class TestHelperFunctions:
|
|||||||
|
|
||||||
def test_create_dit_stage_config(self):
|
def test_create_dit_stage_config(self):
|
||||||
"""Test create_dit_stage_config helper function."""
|
"""Test create_dit_stage_config helper function."""
|
||||||
dit_config = DiTConfig(
|
dit_config = DiTConfig(num_inference_steps=50)
|
||||||
model_type="dit",
|
|
||||||
scheduler_type="ddpm",
|
|
||||||
num_inference_steps=50
|
|
||||||
)
|
|
||||||
|
|
||||||
config = create_dit_stage_config(
|
config = create_dit_stage_config(
|
||||||
stage_id=1,
|
stage_id=1, model_path="test-dit-model", dit_config=dit_config
|
||||||
model_path="test-dit-model",
|
|
||||||
dit_config=dit_config
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert config.stage_id == 1
|
assert config.stage_id == 1
|
||||||
@@ -176,4 +158,3 @@ class TestHelperFunctions:
|
|||||||
assert config.input_modalities == ["text"]
|
assert config.input_modalities == ["text"]
|
||||||
assert config.output_modalities == ["image"]
|
assert config.output_modalities == ["image"]
|
||||||
assert config.dit_config is not None
|
assert config.dit_config is not None
|
||||||
|
|
||||||
+12
-11
@@ -1,45 +1,46 @@
|
|||||||
"""
|
"""
|
||||||
vLLM-omni: Multi-modality models inference and serving with non-autoregressive structures.
|
vLLM-omni: Multi-modality models inference and serving with
|
||||||
|
non-autoregressive structures.
|
||||||
|
|
||||||
This package extends vLLM beyond traditional text-based, autoregressive generation
|
This package extends vLLM beyond traditional text-based, autoregressive
|
||||||
to support multi-modality models with non-autoregressive structures and non-textual outputs.
|
generation to support multi-modality models with non-autoregressive
|
||||||
|
structures and non-textual outputs.
|
||||||
|
|
||||||
Architecture:
|
Architecture:
|
||||||
- 🟡 Modified: vLLM components modified for multimodal support
|
- 🟡 Modified: vLLM components modified for multimodal support
|
||||||
- 🔴 Added: New components for multimodal and non-autoregressive processing
|
- 🔴 Added: New components for multimodal and non-autoregressive
|
||||||
|
processing
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.0"
|
||||||
__author__ = "vLLM-omni Team"
|
__author__ = "vLLM-omni Team"
|
||||||
__email__ = "hsliuustc@gmail.com"
|
__email__ = "hsliuustc@gmail.com"
|
||||||
|
|
||||||
# Main entry points
|
|
||||||
from .entrypoints.omni_llm import OmniLLM, AsyncOmniLLM
|
|
||||||
from .config import (
|
from .config import (
|
||||||
OmniStageConfig,
|
|
||||||
DiTConfig,
|
|
||||||
DiTCacheConfig,
|
DiTCacheConfig,
|
||||||
|
DiTConfig,
|
||||||
|
OmniStageConfig,
|
||||||
create_ar_stage_config,
|
create_ar_stage_config,
|
||||||
create_dit_stage_config,
|
create_dit_stage_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Main entry points
|
||||||
|
from .entrypoints.omni_llm import AsyncOmniLLM, OmniLLM
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# Version info
|
# Version info
|
||||||
"__version__",
|
"__version__",
|
||||||
"__author__",
|
"__author__",
|
||||||
"__email__",
|
"__email__",
|
||||||
|
|
||||||
# Main components
|
# Main components
|
||||||
"OmniLLM",
|
"OmniLLM",
|
||||||
"AsyncOmniLLM",
|
"AsyncOmniLLM",
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
"OmniStageConfig",
|
"OmniStageConfig",
|
||||||
"DiTConfig",
|
"DiTConfig",
|
||||||
"DiTCacheConfig",
|
"DiTCacheConfig",
|
||||||
"create_ar_stage_config",
|
"create_ar_stage_config",
|
||||||
"create_dit_stage_config",
|
"create_dit_stage_config",
|
||||||
|
|
||||||
# All other components are available through their respective modules
|
# All other components are available through their respective modules
|
||||||
# processors.*, schedulers.*, executors.*, etc.
|
# processors.*, schedulers.*, executors.*, etc.
|
||||||
]
|
]
|
||||||
@@ -11,10 +11,10 @@ from vllm.config import config
|
|||||||
import vllm_omni.model_executor.models as me_models
|
import vllm_omni.model_executor.models as me_models
|
||||||
|
|
||||||
from .stage_config import (
|
from .stage_config import (
|
||||||
OmniStageConfig,
|
|
||||||
DiTConfig,
|
|
||||||
DiTCacheConfig,
|
DiTCacheConfig,
|
||||||
DiTCacheTensor,
|
DiTCacheTensor,
|
||||||
|
DiTConfig,
|
||||||
|
OmniStageConfig,
|
||||||
create_ar_stage_config,
|
create_ar_stage_config,
|
||||||
create_dit_stage_config,
|
create_dit_stage_config,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,19 +3,22 @@ Stage configuration for vLLM-omni multi-stage processing.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List, Optional, Type, Literal, Any, Dict
|
from typing import Any, Dict, List, Literal, Optional, Type
|
||||||
|
|
||||||
from vllm.config import (
|
from vllm.config import (
|
||||||
VllmConfig,
|
CompilationConfig,
|
||||||
DeviceConfig,
|
DeviceConfig,
|
||||||
LoadConfig,
|
LoadConfig,
|
||||||
ModelConfig,
|
ModelConfig,
|
||||||
CompilationConfig,
|
VllmConfig,
|
||||||
)
|
)
|
||||||
from vllm.executor.executor_base import ExecutorBase as Executor
|
from vllm.executor.executor_base import ExecutorBase as Executor
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DiTCacheTensor:
|
class DiTCacheTensor:
|
||||||
"""Configuration for DiT cache tensors."""
|
"""Configuration for DiT cache tensors."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
shape: List[int]
|
shape: List[int]
|
||||||
dtype: str = "float32"
|
dtype: str = "float32"
|
||||||
@@ -25,6 +28,7 @@ class DiTCacheTensor:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class DiTCacheConfig:
|
class DiTCacheConfig:
|
||||||
"""Configuration for DiT caching system."""
|
"""Configuration for DiT caching system."""
|
||||||
|
|
||||||
cache_tensors: List[DiTCacheTensor]
|
cache_tensors: List[DiTCacheTensor]
|
||||||
max_cache_size: int = 1024 * 1024 * 1024 # 1GB
|
max_cache_size: int = 1024 * 1024 * 1024 # 1GB
|
||||||
cache_strategy: str = "fifo" # fifo, lru, lfu
|
cache_strategy: str = "fifo" # fifo, lru, lfu
|
||||||
@@ -77,7 +81,9 @@ class OmniStageConfig:
|
|||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
"""Validate configuration after initialization."""
|
"""Validate configuration after initialization."""
|
||||||
if self.engine_type not in ["AR", "DiT"]:
|
if self.engine_type not in ["AR", "DiT"]:
|
||||||
raise ValueError(f"Invalid engine_type: {self.engine_type}. Must be 'AR' or 'DiT'")
|
raise ValueError(
|
||||||
|
f"Invalid engine_type: {self.engine_type}. Must be 'AR' or 'DiT'"
|
||||||
|
)
|
||||||
|
|
||||||
if self.engine_type == "DiT" and self.dit_config is None:
|
if self.engine_type == "DiT" and self.dit_config is None:
|
||||||
raise ValueError("DiT engine requires dit_config")
|
raise ValueError("DiT engine requires dit_config")
|
||||||
@@ -95,16 +101,23 @@ class OmniStageConfig:
|
|||||||
|
|
||||||
if self.engine_type == "AR":
|
if self.engine_type == "AR":
|
||||||
from vllm.executor.uniproc_executor import UniProcExecutor
|
from vllm.executor.uniproc_executor import UniProcExecutor
|
||||||
|
|
||||||
return UniProcExecutor
|
return UniProcExecutor
|
||||||
elif self.engine_type == "DiT":
|
elif self.engine_type == "DiT":
|
||||||
if self.dit_config and self.dit_config.use_diffusers:
|
if self.dit_config and self.dit_config.use_diffusers:
|
||||||
from vllm_omni.executor.diffusers_executor import DiffusersPipelineExecutor
|
from vllm_omni.executor.diffusers_executor import (
|
||||||
|
DiffusersPipelineExecutor,
|
||||||
|
)
|
||||||
|
|
||||||
return DiffusersPipelineExecutor
|
return DiffusersPipelineExecutor
|
||||||
else:
|
else:
|
||||||
from vllm.executor.uniproc_executor import UniProcExecutor
|
from vllm.executor.uniproc_executor import UniProcExecutor
|
||||||
|
|
||||||
return UniProcExecutor
|
return UniProcExecutor
|
||||||
|
|
||||||
raise ValueError(f"No executor class available for engine_type: {self.engine_type}")
|
raise ValueError(
|
||||||
|
f"No executor class available for engine_type: {self.engine_type}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_ar_stage_config(
|
def create_ar_stage_config(
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
"""
|
"""
|
||||||
DiT Cache Manager for vLLM-omni.
|
DiT Cache Manager for vLLM-omni.
|
||||||
|
|
||||||
This module provides caching functionality for DiT (Diffusion Transformer) models
|
This module provides caching functionality for DiT (Diffusion Transformer)
|
||||||
to optimize inference performance and memory usage.
|
models to optimize inference performance and memory usage.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from typing import Dict, List, Optional, Any
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from ..config import DiTCacheConfig, DiTCacheTensor
|
from ..config import DiTCacheConfig, DiTCacheTensor
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ class DiTCacheManager:
|
|||||||
tensor=tensor,
|
tensor=tensor,
|
||||||
timestamp=time.time(),
|
timestamp=time.time(),
|
||||||
access_count=0,
|
access_count=0,
|
||||||
size_bytes=size * 4 # Assuming float32
|
size_bytes=size * 4, # Assuming float32
|
||||||
)
|
)
|
||||||
|
|
||||||
self.cache_tensors[request_id] = cache_tensor
|
self.cache_tensors[request_id] = cache_tensor
|
||||||
@@ -74,7 +75,7 @@ class DiTCacheManager:
|
|||||||
tensor=tensor,
|
tensor=tensor,
|
||||||
timestamp=time.time(),
|
timestamp=time.time(),
|
||||||
access_count=old_tensor.access_count,
|
access_count=old_tensor.access_count,
|
||||||
size_bytes=new_size_bytes
|
size_bytes=new_size_bytes,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Create new cache entry
|
# Create new cache entry
|
||||||
@@ -87,7 +88,7 @@ class DiTCacheManager:
|
|||||||
tensor=tensor,
|
tensor=tensor,
|
||||||
timestamp=time.time(),
|
timestamp=time.time(),
|
||||||
access_count=0,
|
access_count=0,
|
||||||
size_bytes=new_size_bytes
|
size_bytes=new_size_bytes,
|
||||||
)
|
)
|
||||||
self.current_cache_size += new_size_bytes
|
self.current_cache_size += new_size_bytes
|
||||||
|
|
||||||
@@ -127,8 +128,10 @@ class DiTCacheManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Find oldest entry
|
# Find oldest entry
|
||||||
oldest_key = min(self.cache_tensors.keys(),
|
oldest_key = min(
|
||||||
key=lambda k: self.cache_tensors[k].timestamp)
|
self.cache_tensors.keys(),
|
||||||
|
key=lambda k: self.cache_tensors[k].timestamp,
|
||||||
|
)
|
||||||
self.release_cache(oldest_key)
|
self.release_cache(oldest_key)
|
||||||
|
|
||||||
def _evict_lru(self) -> None:
|
def _evict_lru(self) -> None:
|
||||||
@@ -137,8 +140,10 @@ class DiTCacheManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Find least recently used entry
|
# Find least recently used entry
|
||||||
lru_key = min(self.cache_tensors.keys(),
|
lru_key = min(
|
||||||
key=lambda k: self.cache_tensors[k].access_count)
|
self.cache_tensors.keys(),
|
||||||
|
key=lambda k: self.cache_tensors[k].access_count,
|
||||||
|
)
|
||||||
self.release_cache(lru_key)
|
self.release_cache(lru_key)
|
||||||
|
|
||||||
def _evict_lfu(self) -> None:
|
def _evict_lfu(self) -> None:
|
||||||
@@ -147,8 +152,10 @@ class DiTCacheManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Find least frequently used entry
|
# Find least frequently used entry
|
||||||
lfu_key = min(self.cache_tensors.keys(),
|
lfu_key = min(
|
||||||
key=lambda k: self.cache_tensors[k].access_count)
|
self.cache_tensors.keys(),
|
||||||
|
key=lambda k: self.cache_tensors[k].access_count,
|
||||||
|
)
|
||||||
self.release_cache(lfu_key)
|
self.release_cache(lfu_key)
|
||||||
|
|
||||||
def get_statistics(self) -> Dict[str, Any]:
|
def get_statistics(self) -> Dict[str, Any]:
|
||||||
@@ -163,7 +170,7 @@ class DiTCacheManager:
|
|||||||
"cache_hits": self.cache_hits,
|
"cache_hits": self.cache_hits,
|
||||||
"cache_misses": self.cache_misses,
|
"cache_misses": self.cache_misses,
|
||||||
"hit_rate": hit_rate,
|
"hit_rate": hit_rate,
|
||||||
"num_cached_tensors": len(self.cache_tensors)
|
"num_cached_tensors": len(self.cache_tensors),
|
||||||
}
|
}
|
||||||
|
|
||||||
def clear_all_cache(self) -> None:
|
def clear_all_cache(self) -> None:
|
||||||
|
|||||||
@@ -7,8 +7,9 @@ class OmniScheduler(VLLMScheduler):
|
|||||||
"""
|
"""
|
||||||
OmniScheduler: Scheduler for vLLM-omni multimodal processing.
|
OmniScheduler: Scheduler for vLLM-omni multimodal processing.
|
||||||
|
|
||||||
This scheduler extends vLLM's scheduler to support multimodal and non-autoregressive
|
This scheduler extends vLLM's scheduler to support multimodal and
|
||||||
processing with additional fields and methods specific to vLLM-omni.
|
non-autoregressive processing with additional fields and methods
|
||||||
|
specific to vLLM-omni.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Ensure scheduled_new_reqs carry omni-specific payloads (e.g., additional_information)
|
# Ensure scheduled_new_reqs carry omni-specific payloads (e.g., additional_information)
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ from __future__ import annotations
|
|||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from ..config import DiTConfig
|
from ..config import DiTConfig
|
||||||
from ..worker.gpu_diffusion_worker import (
|
from ..worker.gpu_diffusion_worker import DiffusionGPUWorker, DiffusionRunnerOutput
|
||||||
DiffusionGPUWorker,
|
|
||||||
DiffusionRunnerOutput,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DiffusionEngine:
|
class DiffusionEngine:
|
||||||
@@ -27,14 +24,12 @@ class DiffusionEngine:
|
|||||||
config_model_path = None
|
config_model_path = None
|
||||||
if model_cfg is not None:
|
if model_cfg is not None:
|
||||||
if isinstance(model_cfg, dict):
|
if isinstance(model_cfg, dict):
|
||||||
config_model_path = (
|
config_model_path = model_cfg.get("model") or model_cfg.get(
|
||||||
model_cfg.get("model")
|
"model_path"
|
||||||
or model_cfg.get("model_path")
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
config_model_path = (
|
config_model_path = getattr(model_cfg, "model", None) or getattr(
|
||||||
getattr(model_cfg, "model", None)
|
model_cfg, "model_path", None
|
||||||
or getattr(model_cfg, "model_path", None)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.model_path = model_path or config_model_path
|
self.model_path = model_path or config_model_path
|
||||||
@@ -116,9 +111,7 @@ class DiffusersPipelineEngine(DiffusionEngine):
|
|||||||
else self.num_inference_steps
|
else self.num_inference_steps
|
||||||
)
|
)
|
||||||
guidance = (
|
guidance = (
|
||||||
float(guidance_scale)
|
float(guidance_scale) if guidance_scale is not None else self.guidance_scale
|
||||||
if guidance_scale is not None
|
|
||||||
else self.guidance_scale
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.worker.generate(
|
return self.worker.generate(
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ API server for vLLM-omni.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import Dict, Any, List
|
from typing import Any, Dict, List
|
||||||
from fastapi import FastAPI, HTTPException
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
from pydantic import BaseModel
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
from fastapi import FastAPI, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from .omni_llm import AsyncOmniLLM
|
from .omni_llm import AsyncOmniLLM
|
||||||
|
|
||||||
|
|
||||||
class GenerateRequest(BaseModel):
|
class GenerateRequest(BaseModel):
|
||||||
"""Request model for generation."""
|
"""Request model for generation."""
|
||||||
|
|
||||||
prompts: List[str]
|
prompts: List[str]
|
||||||
max_tokens: int = 100
|
max_tokens: int = 100
|
||||||
temperature: float = 0.7
|
temperature: float = 0.7
|
||||||
@@ -22,6 +23,7 @@ class GenerateRequest(BaseModel):
|
|||||||
|
|
||||||
class GenerateResponse(BaseModel):
|
class GenerateResponse(BaseModel):
|
||||||
"""Response model for generation."""
|
"""Response model for generation."""
|
||||||
|
|
||||||
outputs: List[Dict[str, Any]]
|
outputs: List[Dict[str, Any]]
|
||||||
stage_outputs: List[Dict[str, Any]] = None
|
stage_outputs: List[Dict[str, Any]] = None
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ class GenerateResponse(BaseModel):
|
|||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="vLLM-omni API",
|
title="vLLM-omni API",
|
||||||
description="Multi-modality models inference and serving",
|
description="Multi-modality models inference and serving",
|
||||||
version="0.1.0"
|
version="0.1.0",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Global omni_llm instance
|
# Global omni_llm instance
|
||||||
@@ -55,41 +57,44 @@ async def generate(request: GenerateRequest):
|
|||||||
if request.stage_args is None:
|
if request.stage_args is None:
|
||||||
# Create default stage arguments - one per stage config
|
# Create default stage arguments - one per stage config
|
||||||
# For now, we'll process all prompts in the first stage
|
# For now, we'll process all prompts in the first stage
|
||||||
stage_args = [{
|
stage_args = [
|
||||||
"prompt": " ".join(request.prompts) if request.prompts else "",
|
{
|
||||||
"max_tokens": request.max_tokens,
|
"prompt": " ".join(request.prompts) if request.prompts else "",
|
||||||
"temperature": request.temperature
|
"max_tokens": request.max_tokens,
|
||||||
}]
|
"temperature": request.temperature,
|
||||||
|
}
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
stage_args = request.stage_args
|
stage_args = request.stage_args
|
||||||
|
|
||||||
# Generate using omni_llm
|
# Generate using omni_llm
|
||||||
try:
|
try:
|
||||||
outputs = await omni_llm.generate_async(stage_args)
|
outputs = await omni_llm.generate_async(stage_args)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
# Fallback to synchronous generation
|
# Fallback to synchronous generation
|
||||||
outputs = omni_llm.generate(stage_args)
|
outputs = omni_llm.generate(stage_args)
|
||||||
|
|
||||||
# Convert outputs to response format
|
# Convert outputs to response format
|
||||||
response_outputs = []
|
response_outputs = []
|
||||||
for output in outputs:
|
for output in outputs:
|
||||||
if hasattr(output, 'outputs') and output.outputs:
|
if hasattr(output, "outputs") and output.outputs:
|
||||||
for out in output.outputs:
|
for out in output.outputs:
|
||||||
response_outputs.append({
|
response_outputs.append(
|
||||||
"text": getattr(out, 'text', ''),
|
{
|
||||||
"finished": getattr(out, 'finish_reason', 'length') != 'length',
|
"text": getattr(out, "text", ""),
|
||||||
"tokens": getattr(out, 'token_ids', [])
|
"finished": getattr(out, "finish_reason", "length")
|
||||||
})
|
!= "length",
|
||||||
|
"tokens": getattr(out, "token_ids", []),
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
response_outputs.append({
|
response_outputs.append({"text": "", "finished": True, "tokens": []})
|
||||||
"text": "",
|
|
||||||
"finished": True,
|
|
||||||
"tokens": []
|
|
||||||
})
|
|
||||||
|
|
||||||
return GenerateResponse(
|
return GenerateResponse(
|
||||||
outputs=response_outputs,
|
outputs=response_outputs,
|
||||||
stage_outputs=[{"stage": i, "output": "processed"} for i in range(len(stage_args))]
|
stage_outputs=[
|
||||||
|
{"stage": i, "output": "processed"} for i in range(len(stage_args))
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -111,31 +116,30 @@ async def get_info():
|
|||||||
return {
|
return {
|
||||||
"service": "vllm-omni",
|
"service": "vllm-omni",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"num_stages": omni_llm.get_num_stages() if hasattr(omni_llm, 'get_num_stages') else 0,
|
"num_stages": omni_llm.get_num_stages()
|
||||||
|
if hasattr(omni_llm, "get_num_stages")
|
||||||
|
else 0,
|
||||||
"stage_configs": [
|
"stage_configs": [
|
||||||
{
|
{
|
||||||
"stage_id": config.stage_id,
|
"stage_id": config.stage_id,
|
||||||
"engine_type": config.engine_type,
|
"engine_type": config.engine_type,
|
||||||
"model_path": config.model_path,
|
"model_path": config.model_path,
|
||||||
"input_modalities": config.input_modalities,
|
"input_modalities": config.input_modalities,
|
||||||
"output_modalities": config.output_modalities
|
"output_modalities": config.output_modalities,
|
||||||
}
|
}
|
||||||
for config in omni_llm.stage_configs
|
for config in omni_llm.stage_configs
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def run_server(omni_llm_instance: AsyncOmniLLM, host: str = "0.0.0.0", port: int = 8000):
|
async def run_server(
|
||||||
|
omni_llm_instance: AsyncOmniLLM, host: str = "0.0.0.0", port: int = 8000
|
||||||
|
):
|
||||||
"""Run the API server."""
|
"""Run the API server."""
|
||||||
global omni_llm
|
global omni_llm
|
||||||
omni_llm = omni_llm_instance
|
omni_llm = omni_llm_instance
|
||||||
|
|
||||||
config = uvicorn.Config(
|
config = uvicorn.Config(app=app, host=host, port=port, log_level="info")
|
||||||
app=app,
|
|
||||||
host=host,
|
|
||||||
port=port,
|
|
||||||
log_level="info"
|
|
||||||
)
|
|
||||||
|
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
await server.serve()
|
await server.serve()
|
||||||
|
|||||||
@@ -3,8 +3,7 @@ CLI entry point for vLLM-omni that intercepts vLLM commands.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
from typing import List, Optional
|
|
||||||
from vllm_omni.entrypoints.cli.serve import OmniServeCommand
|
from vllm_omni.entrypoints.cli.serve import OmniServeCommand
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +18,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
# Forward to original vLLM CLI
|
# Forward to original vLLM CLI
|
||||||
from vllm.entrypoints.cli.main import main as vllm_main
|
from vllm.entrypoints.cli.main import main as vllm_main
|
||||||
|
|
||||||
vllm_main()
|
vllm_main()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,11 @@ Omni serve command for vLLM-omni.
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import List, Optional
|
from typing import List
|
||||||
|
|
||||||
|
from vllm_omni.config import DiTConfig, create_ar_stage_config, create_dit_stage_config
|
||||||
|
|
||||||
from ..omni_llm import AsyncOmniLLM
|
from ..omni_llm import AsyncOmniLLM
|
||||||
from vllm_omni.config import (
|
|
||||||
DiTConfig,
|
|
||||||
create_ar_stage_config,
|
|
||||||
create_dit_stage_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class OmniServeCommand:
|
class OmniServeCommand:
|
||||||
@@ -31,7 +28,7 @@ class OmniServeCommand:
|
|||||||
"model",
|
"model",
|
||||||
nargs="?",
|
nargs="?",
|
||||||
default="Qwen/Qwen3-0.6B",
|
default="Qwen/Qwen3-0.6B",
|
||||||
help="Path to the model or model name (default: Qwen/Qwen3-0.6B)"
|
help="Path to the model or model name (default: Qwen/Qwen3-0.6B)",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Server arguments
|
# Server arguments
|
||||||
@@ -39,54 +36,44 @@ class OmniServeCommand:
|
|||||||
"--port",
|
"--port",
|
||||||
type=int,
|
type=int,
|
||||||
default=8000,
|
default=8000,
|
||||||
help="Port to run the server on"
|
help="Port to run the server on",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--host",
|
"--host",
|
||||||
type=str,
|
type=str,
|
||||||
default="0.0.0.0",
|
default="0.0.0.0",
|
||||||
help="Host to run the server on"
|
help="Host to run the server on",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Stage configuration arguments
|
# Stage configuration arguments
|
||||||
parser.add_argument(
|
parser.add_argument("--ar-stage", type=str, help="AR stage model path")
|
||||||
"--ar-stage",
|
|
||||||
type=str,
|
|
||||||
help="AR stage model path"
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument("--dit-stage", type=str, help="DiT stage model path")
|
||||||
"--dit-stage",
|
|
||||||
type=str,
|
|
||||||
help="DiT stage model path"
|
|
||||||
)
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--dit-steps",
|
"--dit-steps",
|
||||||
type=int,
|
type=int,
|
||||||
default=50,
|
default=50,
|
||||||
help="Number of DiT inference steps"
|
help="Number of DiT inference steps",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--dit-guidance-scale",
|
"--dit-guidance-scale",
|
||||||
type=float,
|
type=float,
|
||||||
default=7.5,
|
default=7.5,
|
||||||
help="DiT guidance scale"
|
help="DiT guidance scale",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--use-diffusers",
|
"--use-diffusers",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Use diffusers pipeline for DiT stage"
|
help="Use diffusers pipeline for DiT stage",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Other arguments
|
# Other arguments
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--log-stats",
|
"--log-stats", action="store_true", help="Enable logging statistics"
|
||||||
action="store_true",
|
|
||||||
help="Enable logging statistics"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
@@ -100,8 +87,7 @@ class OmniServeCommand:
|
|||||||
|
|
||||||
# Create AsyncOmniLLM instance
|
# Create AsyncOmniLLM instance
|
||||||
omni_llm = AsyncOmniLLM(
|
omni_llm = AsyncOmniLLM(
|
||||||
stage_configs=stage_configs,
|
stage_configs=stage_configs, log_stats=parsed_args.log_stats
|
||||||
log_stats=parsed_args.log_stats
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Start the server
|
# Start the server
|
||||||
@@ -118,7 +104,7 @@ class OmniServeCommand:
|
|||||||
stage_id=stage_id,
|
stage_id=stage_id,
|
||||||
model_path=ar_model,
|
model_path=ar_model,
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
stage_configs.append(ar_config)
|
stage_configs.append(ar_config)
|
||||||
stage_id += 1
|
stage_id += 1
|
||||||
@@ -145,7 +131,7 @@ class OmniServeCommand:
|
|||||||
model_path=dit_model,
|
model_path=dit_model,
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["image"],
|
output_modalities=["image"],
|
||||||
dit_config=dit_config
|
dit_config=dit_config,
|
||||||
)
|
)
|
||||||
stage_configs.append(dit_stage_config)
|
stage_configs.append(dit_stage_config)
|
||||||
stage_id += 1
|
stage_id += 1
|
||||||
@@ -159,7 +145,7 @@ class OmniServeCommand:
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path=args.model,
|
model_path=args.model,
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
stage_configs.append(ar_config)
|
stage_configs.append(ar_config)
|
||||||
|
|
||||||
@@ -175,7 +161,7 @@ class OmniServeCommand:
|
|||||||
model_path=args.model,
|
model_path=args.model,
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["image"],
|
output_modalities=["image"],
|
||||||
dit_config=dit_config
|
dit_config=dit_config,
|
||||||
)
|
)
|
||||||
stage_configs.append(dit_stage_config)
|
stage_configs.append(dit_stage_config)
|
||||||
else:
|
else:
|
||||||
@@ -184,7 +170,7 @@ class OmniServeCommand:
|
|||||||
stage_id=0,
|
stage_id=0,
|
||||||
model_path=args.model,
|
model_path=args.model,
|
||||||
input_modalities=["text"],
|
input_modalities=["text"],
|
||||||
output_modalities=["text"]
|
output_modalities=["text"],
|
||||||
)
|
)
|
||||||
stage_configs.append(ar_config)
|
stage_configs.append(ar_config)
|
||||||
|
|
||||||
@@ -196,11 +182,7 @@ class OmniServeCommand:
|
|||||||
# Import here to avoid circular imports
|
# Import here to avoid circular imports
|
||||||
from vllm_omni.entrypoints.api_server import run_server
|
from vllm_omni.entrypoints.api_server import run_server
|
||||||
|
|
||||||
await run_server(
|
await run_server(omni_llm_instance=omni_llm, host=args.host, port=args.port)
|
||||||
omni_llm_instance=omni_llm,
|
|
||||||
host=args.host,
|
|
||||||
port=args.port
|
|
||||||
)
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nShutting down server...")
|
print("\nShutting down server...")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in new issue
Block a user