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
9 changes: 2 additions & 7 deletions awex/converter/sglang_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# specific language governing permissions and limitations
# under the License.

import os
from typing import List, Tuple

import torch
from transformers import PretrainedConfig

from awex.converter.weights_converter import append_scale_inv, normalize_scale_inv_name
from awex.util import device as device_util


# all sglang related imports must be local imports to avoid import error if
Expand Down Expand Up @@ -62,12 +62,7 @@ def _resolve_device_backend(self, infer_engine_config) -> str:
comm_backend = self._cfg_value(infer_engine_config, "comm_backend", None)
if isinstance(comm_backend, str) and comm_backend.strip().lower() == "hccl":
return "npu"
env_backend = os.environ.get("AWEX_DEVICE_TYPE", "").strip().lower()
if env_backend in {"cuda", "npu", "cpu"}:
return env_backend
if os.environ.get("ASCEND_RT_VISIBLE_DEVICES"):
return "npu"
return "cuda"
return device_util.get_device_type()

def _use_transposed_moe_layout(self, name: str, parameter: torch.Tensor) -> bool:
if self.device_backend != "npu" or parameter.ndim != 2:
Expand Down
16 changes: 16 additions & 0 deletions awex/tests/test_qwen3_moe_sglang_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from awex.models.qwen3_moe import SGlangToHFWeightConverterQwen3Moe
from awex.models.registry import get_infer_weights_converter
from awex.util import device as device_util

# Tiny Qwen3-MoE-like geometry: GQA with 8 query heads and 2 KV heads.
NUM_HEADS = 8
Expand Down Expand Up @@ -67,6 +68,21 @@ def _make_converter(tp_size=1, ep_size=1, tp_rank=0, ep_rank=0):
)


def test_backend_uses_available_cuda_when_visibility_envs_overlap(monkeypatch):
monkeypatch.delenv("AWEX_DEVICE_TYPE", raising=False)
monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "0")
monkeypatch.setenv("ASCEND_RT_VISIBLE_DEVICES", "0")
monkeypatch.setattr(device_util, "is_npu_available", lambda: False)
monkeypatch.setattr(device_util, "is_cuda_available", lambda: True)
infer_engine_config = SimpleNamespace(tp_size=1, ep_size=1)

converter = SGlangToHFWeightConverterQwen3Moe(
_model_config(), infer_engine_config, _rank_info()
)

assert converter.device_backend == "cuda"


def _sglang_named_params(num_local_experts=NUM_EXPERTS):
"""Parameter names/shapes as exposed by SGLang for one decoder layer."""
qkv_rows = (NUM_HEADS + 2 * NUM_KV_HEADS) * HEAD_DIM
Expand Down
Loading