Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion vllm_omni/model_executor/models/cosyvoice3/cosyvoice3.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
unpad_prompt_conditioning,
)
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform
from vllm_omni.transformers_utils.configs.cosyvoice3 import CosyVoice3Config
from vllm_omni.utils.speaker_cache import get_speaker_cache

Expand Down Expand Up @@ -198,7 +199,7 @@ def _ensure_s3_model(cls):
) from e

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good move to use platform-agnostic device selection

model = _s3.load_model("speech_tokenizer_v3_25hz")
device = "cuda" if torch.cuda.is_available() else "cpu"
device = current_omni_platform.get_torch_device()
model = model.to(device).eval()
cls._s3_model = (model, _s3, device)
return cls._s3_model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DAC_SAMPLE_RATE,
build_dac_codec,
)
from vllm_omni.platforms import current_omni_platform

logger = init_logger(__name__)

Expand Down Expand Up @@ -129,7 +130,7 @@ def encode_reference_audio_codes(
(dtype=torch.long).
"""
if device is None:
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
device = current_omni_platform.get_torch_device()
Comment thread
hsliuustc0106 marked this conversation as resolved.
else:
device = torch.device(device)
dtype = torch.float32
Expand Down
3 changes: 2 additions & 1 deletion vllm_omni/model_executor/models/glm_tts/glm_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

from vllm_omni.model_executor.models.common.nucleus_ras_sampling import ras_sample_one as _ras_sample_one
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform
from vllm_omni.transformers_utils.configs.glm_tts import GLMTTSConfig
from vllm_omni.utils.speaker_cache import get_speaker_cache

Expand Down Expand Up @@ -411,7 +412,7 @@ def _ensure_cached_runtime_components(

# Load voice clone components (speech tokenizer + CampPlus)
if load_voice_clone:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()
self.processor_device = device
campplus_path = getattr(self, "_campplus_path", None) or resolve_glm_tts_campplus_path(model_dir)
self._campplus_path = campplus_path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
load_higgs_audio_codec,
)
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform

__all__ = [
"HiggsAudioV2Code2Wav",
Expand Down Expand Up @@ -173,7 +174,7 @@ def load_codec_from_disk(self, model_dir: str, device: torch.device | None = Non
2. Otherwise fall back to ``<model_dir>/<audio_tokenizer_subdir>``.
"""
if device is None:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()
audio_tokenizer_path = self._resolve_audio_tokenizer_path(model_dir)
quantizer, fc2, acoustic_decoder, _tokenizer_config = load_higgs_audio_codec(audio_tokenizer_path, device)
if len(quantizer.quantizers) != self.num_codebooks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import numpy as np
import torch

from vllm_omni.platforms import current_omni_platform

__all__ = [
"UnsupportedInputError",
"MULTI_SPEAKER_TAG_PATTERN",
Expand Down Expand Up @@ -239,7 +241,7 @@ def _load_audio_tokenizer():
allow_patterns=[f"{_K2_OMNIVOICE_SUBDIR}/*"],
)
audio_tokenizer_dir = os.path.join(repo_path, _K2_OMNIVOICE_SUBDIR)
device = "cuda" if torch.cuda.is_available() else "cpu"
device = current_omni_platform.get_torch_device()
model = HiggsAudioV2TokenizerModel.from_pretrained(audio_tokenizer_dir).to(device)
return model.eval()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
HiggsAudioV3Config,
)
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform

__all__ = [
"HiggsAudioV3Code2Wav",
Expand Down Expand Up @@ -126,7 +127,7 @@ def _load_from_tokenizer_repo(self) -> None:
else:
raise FileNotFoundError(f"No cached snapshot for {tokenizer_id}")

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()
quantizer, fc2, acoustic_decoder, _cfg = load_higgs_audio_codec(tokenizer_dir, device)
self.quantizer = quantizer
self.fc2 = fc2
Expand Down Expand Up @@ -278,7 +279,7 @@ def _load_from_bundled_state(
)

if device is None:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()

# The bundled codec may use boson-ai key naming. Try remapping.
needs_remap = any(k.startswith("quantizer.vq.layers.") for k in codec_state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from vllm_omni.model_executor.models.mimo_audio.cuda_graph_decoder_wrapper import CUDAGraphMiMoDecoderWrapper
from vllm_omni.model_executor.models.mimo_audio.modeling_audio_tokenizer import MiMoAudioTokenizer
from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -442,8 +443,7 @@ def __init__(self, vllm_config: VllmConfig, prefix: str = ""):

self.logits_processor = LogitsProcessor(config.vocab_size)

device_str = "cuda" if torch.cuda.is_available() else "cpu"
self.device = torch.device(device_str)
self.device = current_omni_platform.get_torch_device()
self.sample_rate = getattr(config, "audio_sample_rate", 24000)

self.tokenizer = AutoTokenizer.from_pretrained(self.config.name_or_path, trust_remote_code=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def forward(
device = inputs_embeds.device
else:
num_tokens = 1
device = torch.device("cuda")
device = current_omni_platform.get_torch_device()
hidden_dim = self.config.hidden_size if hasattr(self.config, "hidden_size") else 2560

# Profile/dummy run: both input_ids and inputs_embeds are None.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from vllm.config import VllmConfig
from vllm.model_executor.models.interfaces import SupportsPP

from vllm_omni.platforms import current_omni_platform

try:
from stepaudio2 import Token2wav as _Token2wav

Expand Down Expand Up @@ -379,7 +381,7 @@ def _dummy_hidden_states(
break
else:
num_tokens = 1
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()
hidden_size = int(getattr(self, "_hidden_size", 768) or 768)
return torch.zeros((num_tokens, hidden_size), device=device, dtype=torch.bfloat16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
reinit_rotary_inv_freq,
transformers_keys_to_ignore_compat,
)
from vllm_omni.platforms import current_omni_platform

logger = init_logger(__name__)

Expand Down Expand Up @@ -183,7 +184,7 @@ def __init__(self, *, vllm_config: VllmConfig, prefix: str = "") -> None:
# Eager construction (not in load_weights) -- see module docstring.
_patch_torchaudio_load()

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()
self._device: torch.device = device

if device.type == "cuda" and torch.cuda.is_bf16_supported():
Expand Down
3 changes: 2 additions & 1 deletion vllm_omni/model_executor/models/omnivoice/omnivoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from vllm.sequence import IntermediateTensors

from vllm_omni.model_executor.models.output_templates import OmniOutput
from vllm_omni.platforms import current_omni_platform
from vllm_omni.transformers_utils.configs.omnivoice import OmniVoiceConfig

logger = init_logger(__name__)
Expand Down Expand Up @@ -495,7 +496,7 @@ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
try:
device = next(self.parameters()).device
except StopIteration:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = current_omni_platform.get_torch_device()

model_dir = self._resolve_model_dir()

Expand Down
3 changes: 2 additions & 1 deletion vllm_omni/model_executor/models/qwen3_omni/qwen3_omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Qwen3OmniMoeThinkerProcessingInfo,
)
from vllm_omni.model_executor.models.utils import add_prefix_to_loaded_weights, safe_tensor_reshape
from vllm_omni.platforms import current_omni_platform

# Special token IDs for Qwen3 Omni MoE
# Reference: https://huggingface.co/Qwen/Qwen3-Omni-30B-A3B-Instruct/blob/main/tokenizer_config.json
Expand Down Expand Up @@ -1213,7 +1214,7 @@ def _talker_to_code_predictor(
else (
talker_hidden_states.device
if isinstance(talker_hidden_states, torch.Tensor)
else torch.device("cuda" if torch.cuda.is_available() else "cpu")
else current_omni_platform.get_torch_device()
)
)

Expand Down
4 changes: 4 additions & 0 deletions vllm_omni/platforms/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ class UnspecifiedOmniPlatform(OmniPlatform):
_enum = PlatformEnum.UNSPECIFIED
device_type = "cpu"

@classmethod
def get_torch_device(cls, local_rank: int | None = None) -> torch.device:
return torch.device("cpu")

@classmethod
def get_device_count(cls) -> int:
return 0
3 changes: 2 additions & 1 deletion vllm_omni/worker/gpu_ar_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from vllm.v1.worker.workspace import init_workspace_manager

from vllm_omni.diffusion.data import OmniACK, OmniSleepTask, OmniWakeTask
from vllm_omni.platforms import current_omni_platform
from vllm_omni.worker.base import OmniGPUWorkerBase
from vllm_omni.worker.gpu_ar_model_runner import GPUARModelRunner
from vllm_omni.worker.memory_utils import request_memory_tolerant
Expand Down Expand Up @@ -58,7 +59,7 @@ def init_device(self):
f"be less than or equal to the number of visible devices "
f"({visible_device_count})."
)
self.device = torch.device(f"cuda:{self.local_rank}")
self.device = current_omni_platform.get_torch_device(self.local_rank)
torch.accelerator.set_device_index(self.device)

current_platform.check_if_supports_dtype(self.model_config.dtype)
Expand Down
3 changes: 2 additions & 1 deletion vllm_omni/worker/gpu_generation_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from vllm.v1.worker.gpu_worker import init_worker_distributed_environment
from vllm.v1.worker.workspace import init_workspace_manager

from vllm_omni.platforms import current_omni_platform
from vllm_omni.worker.base import OmniGPUWorkerBase
from vllm_omni.worker.gpu_generation_model_runner import GPUGenerationModelRunner
from vllm_omni.worker.memory_utils import request_memory_tolerant
Expand Down Expand Up @@ -57,7 +58,7 @@ def init_device(self):
f"be less than or equal to the number of visible devices "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent platform-agnostic device selection - good

f"({visible_device_count})."
)
self.device = torch.device(f"cuda:{self.local_rank}")
self.device = current_omni_platform.get_torch_device(self.local_rank)
torch.accelerator.set_device_index(self.device)

current_platform.check_if_supports_dtype(self.model_config.dtype)
Expand Down