[CI] Allowlist-shrink batch 2: wire 9 tests/models/ files into Buildkite, fix 2 stale bugs found (#59050)
Signed-off-by: Turner Jabbour <doubleujabbour@gmail.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
ef014bdf06
commit
aecb717f10
@@ -85,6 +85,7 @@ def test_dspark_markov_head_is_replicated(
|
||||
assert head.markov_w2.tp_size == 1
|
||||
assert head.markov_w1.weight.shape == (128, 8)
|
||||
assert head.markov_w2.weight.shape == (128, 8)
|
||||
head.markov_w2.quant_method.process_weights_after_loading(head.markov_w2)
|
||||
|
||||
def fail_collective(*args, **kwargs):
|
||||
raise AssertionError("replicated Markov head must not invoke TP collectives")
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
is set and the symbol exists, and otherwise falls back to
|
||||
`vllm.model_executor.layers.<module>`. These tests pin that contract and the
|
||||
logging that reports which source was used.
|
||||
|
||||
CPU-only: no engine is built. The end-to-end counterpart that serves a model
|
||||
through `vllm_runner` lives in `test_layer_registry_e2e.py` (GPU job).
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -14,7 +17,6 @@ import sys
|
||||
import types
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from vllm.model_executor.models.transformers import layers
|
||||
|
||||
@@ -42,16 +44,16 @@ def test_falls_back_to_vllm_when_disabled(monkeypatch, fake_hw_layernorm):
|
||||
assert layers._resolve("layernorm", "RMSNorm") is VllmRMSNorm
|
||||
|
||||
|
||||
def test_uses_hw_agnostic_when_enabled(monkeypatch, fake_hw_layernorm, caplog):
|
||||
def test_uses_hw_agnostic_when_enabled(monkeypatch, fake_hw_layernorm, caplog_vllm):
|
||||
"""Enabled and available: the hw-agnostic class is used and logged."""
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "1")
|
||||
with caplog.at_level(logging.INFO):
|
||||
with caplog_vllm.at_level(logging.INFO):
|
||||
resolved = layers._resolve("layernorm", "RMSNorm")
|
||||
assert resolved is fake_hw_layernorm.RMSNorm
|
||||
assert "Using hw-agnostic layer: RMSNorm" in caplog.text
|
||||
assert "Using hw-agnostic layer: RMSNorm" in caplog_vllm.text
|
||||
|
||||
|
||||
def test_falls_back_when_symbol_missing(monkeypatch, caplog):
|
||||
def test_falls_back_when_symbol_missing(monkeypatch, caplog_vllm):
|
||||
"""Enabled but the symbol is not ported: fall back to vLLM and warn."""
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "1")
|
||||
# A hw-agnostic module without the requested attribute triggers fallback.
|
||||
@@ -59,10 +61,10 @@ def test_falls_back_when_symbol_missing(monkeypatch, caplog):
|
||||
monkeypatch.setitem(sys.modules, HW_MODULE, empty)
|
||||
from vllm.model_executor.layers.layernorm import RMSNorm as VllmRMSNorm
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
with caplog_vllm.at_level(logging.WARNING):
|
||||
resolved = layers._resolve("layernorm", "RMSNorm")
|
||||
assert resolved is VllmRMSNorm
|
||||
assert "falling back to default" in caplog.text
|
||||
assert "falling back to default" in caplog_vllm.text
|
||||
|
||||
|
||||
def test_act_and_mul_falls_back_for_unknown_activation(
|
||||
@@ -76,102 +78,3 @@ def test_act_and_mul_falls_back_for_unknown_activation(
|
||||
from vllm.model_executor.layers.activation import GeluAndMul
|
||||
|
||||
assert isinstance(layers.get_act_and_mul_fn("gelu"), GeluAndMul)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def tiny_llama_path(tmp_path_factory):
|
||||
"""A randomly-initialized microscopic Llama saved to disk (with an ungated
|
||||
tokenizer) so vLLM can load it like any local checkpoint."""
|
||||
from transformers import AutoTokenizer, LlamaConfig, LlamaForCausalLM
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer")
|
||||
config = LlamaConfig(
|
||||
vocab_size=tokenizer.vocab_size,
|
||||
hidden_size=128,
|
||||
intermediate_size=256,
|
||||
num_hidden_layers=2,
|
||||
num_attention_heads=4,
|
||||
rms_norm_eps=1e-6,
|
||||
hidden_act="silu",
|
||||
)
|
||||
torch.manual_seed(0)
|
||||
model = LlamaForCausalLM(config)
|
||||
|
||||
path = tmp_path_factory.mktemp("tiny_llama")
|
||||
model.save_pretrained(path)
|
||||
tokenizer.save_pretrained(path)
|
||||
return str(path)
|
||||
|
||||
|
||||
# Registered names of the layers the backend can
|
||||
# currently route to hw-agnostic implementations.
|
||||
_COVERED_LAYERS = ("rms_norm", "silu_and_mul")
|
||||
|
||||
|
||||
def _layer_providers(model) -> dict[str, str]:
|
||||
"""Map each covered layer type present in the model to the provider its
|
||||
implementation came from (``hw_agnostic`` or ``vllm``).
|
||||
"""
|
||||
|
||||
def provider_of(module) -> str | None:
|
||||
for cls in type(module).__mro__:
|
||||
if "hw_agnostic.layers" in cls.__module__:
|
||||
return "hw_agnostic"
|
||||
if ".model_executor.layers." in cls.__module__:
|
||||
return "vllm"
|
||||
return None
|
||||
|
||||
providers: dict[str, str] = {}
|
||||
for module in model.modules():
|
||||
name = getattr(module, "name", None)
|
||||
if (
|
||||
name in _COVERED_LAYERS
|
||||
and name not in providers
|
||||
and (prov := provider_of(module)) is not None
|
||||
):
|
||||
providers[name] = prov
|
||||
return providers
|
||||
|
||||
|
||||
def _serve(vllm_runner, model_path, prompts):
|
||||
"""Serve the model through the backend; return (layer_providers, logprobs)."""
|
||||
with vllm_runner(
|
||||
model_path,
|
||||
model_impl="transformers",
|
||||
max_model_len=64,
|
||||
enforce_eager=True,
|
||||
gpu_memory_utilization=0.3,
|
||||
) as runner:
|
||||
assert runner.llm.llm_engine.model_config.using_transformers_backend()
|
||||
providers = runner.apply_model(_layer_providers)[0]
|
||||
outputs = runner.generate_greedy_logprobs(
|
||||
prompts, max_tokens=32, num_logprobs=5
|
||||
)
|
||||
return providers, outputs
|
||||
|
||||
|
||||
def test_hw_agnostic_matches_vllm_end_to_end(monkeypatch, vllm_runner, tiny_llama_path):
|
||||
"""Serving the tiny model with hw-agnostic layers matches the vLLM baseline."""
|
||||
# spawn: worker re-imports layers with the env set (see docstring).
|
||||
monkeypatch.setenv("VLLM_WORKER_MULTIPROC_METHOD", "spawn")
|
||||
# apply_model pickles the introspection function.
|
||||
monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1")
|
||||
from ..utils import check_logprobs_close
|
||||
|
||||
prompts = ["The capital of France is", "vLLM is"]
|
||||
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "0")
|
||||
vllm_providers, vllm_outputs = _serve(vllm_runner, tiny_llama_path, prompts)
|
||||
# Both replaceable layers present in a Llama block must be vLLM's here.
|
||||
assert vllm_providers == {"rms_norm": "vllm", "silu_and_mul": "vllm"}
|
||||
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "1")
|
||||
hw_providers, hw_outputs = _serve(vllm_runner, tiny_llama_path, prompts)
|
||||
assert hw_providers == {"rms_norm": "hw_agnostic", "silu_and_mul": "hw_agnostic"}
|
||||
|
||||
check_logprobs_close(
|
||||
outputs_0_lst=vllm_outputs,
|
||||
outputs_1_lst=hw_outputs,
|
||||
name_0="vllm",
|
||||
name_1="hw_agnostic",
|
||||
)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""End-to-end check of the Transformers backend's hw-agnostic layers.
|
||||
|
||||
Serves a tiny Llama through `vllm_runner` with and without
|
||||
`VLLM_USE_HW_AGNOSTIC` and checks the layer providers and logprobs. Needs a
|
||||
real engine, so it runs in the GPU job. The CPU-only unit tests for the
|
||||
resolution logic (`layers._resolve`) are in `test_layer_registry.py`.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def tiny_llama_path(tmp_path_factory):
|
||||
"""A randomly-initialized microscopic Llama saved to disk (with an ungated
|
||||
tokenizer) so vLLM can load it like any local checkpoint."""
|
||||
from transformers import AutoTokenizer, LlamaConfig, LlamaForCausalLM
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer")
|
||||
config = LlamaConfig(
|
||||
vocab_size=tokenizer.vocab_size,
|
||||
hidden_size=128,
|
||||
intermediate_size=256,
|
||||
num_hidden_layers=2,
|
||||
num_attention_heads=4,
|
||||
rms_norm_eps=1e-6,
|
||||
hidden_act="silu",
|
||||
)
|
||||
torch.manual_seed(0)
|
||||
model = LlamaForCausalLM(config)
|
||||
|
||||
path = tmp_path_factory.mktemp("tiny_llama")
|
||||
model.save_pretrained(path)
|
||||
tokenizer.save_pretrained(path)
|
||||
return str(path)
|
||||
|
||||
|
||||
# Registered names of the layers the backend can
|
||||
# currently route to hw-agnostic implementations.
|
||||
_COVERED_LAYERS = ("rms_norm", "silu_and_mul")
|
||||
|
||||
|
||||
def _layer_providers(model) -> dict[str, str]:
|
||||
"""Map each covered layer type present in the model to the provider its
|
||||
implementation came from (``hw_agnostic`` or ``vllm``).
|
||||
"""
|
||||
|
||||
def provider_of(module) -> str | None:
|
||||
for cls in type(module).__mro__:
|
||||
if "hw_agnostic.layers" in cls.__module__:
|
||||
return "hw_agnostic"
|
||||
if ".model_executor.layers." in cls.__module__:
|
||||
return "vllm"
|
||||
return None
|
||||
|
||||
providers: dict[str, str] = {}
|
||||
for module in model.modules():
|
||||
name = getattr(module, "name", None)
|
||||
if (
|
||||
name in _COVERED_LAYERS
|
||||
and name not in providers
|
||||
and (prov := provider_of(module)) is not None
|
||||
):
|
||||
providers[name] = prov
|
||||
return providers
|
||||
|
||||
|
||||
def _serve(vllm_runner, model_path, prompts):
|
||||
"""Serve the model through the backend; return (layer_providers, logprobs)."""
|
||||
with vllm_runner(
|
||||
model_path,
|
||||
model_impl="transformers",
|
||||
max_model_len=64,
|
||||
enforce_eager=True,
|
||||
gpu_memory_utilization=0.3,
|
||||
) as runner:
|
||||
assert runner.llm.llm_engine.model_config.using_transformers_backend()
|
||||
providers = runner.apply_model(_layer_providers)[0]
|
||||
outputs = runner.generate_greedy_logprobs(
|
||||
prompts, max_tokens=32, num_logprobs=5
|
||||
)
|
||||
return providers, outputs
|
||||
|
||||
|
||||
def test_hw_agnostic_matches_vllm_end_to_end(monkeypatch, vllm_runner, tiny_llama_path):
|
||||
"""Serving the tiny model with hw-agnostic layers matches the vLLM baseline."""
|
||||
# spawn: `layers` resolves its symbols at import time, so the worker must
|
||||
# re-import it with VLLM_USE_HW_AGNOSTIC already set (fork would inherit
|
||||
# the parent's already-resolved module).
|
||||
monkeypatch.setenv("VLLM_WORKER_MULTIPROC_METHOD", "spawn")
|
||||
# apply_model pickles the introspection function.
|
||||
monkeypatch.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1")
|
||||
from ..utils import check_logprobs_close
|
||||
|
||||
prompts = ["The capital of France is", "vLLM is"]
|
||||
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "0")
|
||||
vllm_providers, vllm_outputs = _serve(vllm_runner, tiny_llama_path, prompts)
|
||||
# Both replaceable layers present in a Llama block must be vLLM's here.
|
||||
assert vllm_providers == {"rms_norm": "vllm", "silu_and_mul": "vllm"}
|
||||
|
||||
monkeypatch.setenv("VLLM_USE_HW_AGNOSTIC", "1")
|
||||
hw_providers, hw_outputs = _serve(vllm_runner, tiny_llama_path, prompts)
|
||||
assert hw_providers == {"rms_norm": "hw_agnostic", "silu_and_mul": "hw_agnostic"}
|
||||
|
||||
check_logprobs_close(
|
||||
outputs_0_lst=vllm_outputs,
|
||||
outputs_1_lst=hw_outputs,
|
||||
name_0="vllm",
|
||||
name_1="hw_agnostic",
|
||||
)
|
||||
Reference in New Issue
Block a user