Skip to content

Commit 292200f

Browse files
committed
Fix tests
1 parent 03864a5 commit 292200f

3 files changed

Lines changed: 53 additions & 47 deletions

File tree

tests/vec_inf/client/test_engine_selection.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def _set_required_env_vars(self, monkeypatch: pytest.MonkeyPatch) -> None:
2424
monkeypatch.setenv("VEC_INF_ACCOUNT", "test-account")
2525
monkeypatch.setenv("VEC_INF_WORK_DIR", "/tmp")
2626

27+
@pytest.fixture(autouse=True)
28+
def _mock_validate_weights_path(self) -> None:
29+
"""Avoid disk checks for fake model paths in fixtures."""
30+
with patch("vec_inf.client._helper.utils.validate_weights_path"):
31+
yield
32+
2733
@pytest.fixture
2834
def model_config_vllm(self) -> ModelConfig:
2935
"""Fixture providing a vLLM model configuration."""
@@ -187,6 +193,12 @@ def _set_required_env_vars(self, monkeypatch: pytest.MonkeyPatch) -> None:
187193
monkeypatch.setenv("VEC_INF_ACCOUNT", "test-account")
188194
monkeypatch.setenv("VEC_INF_WORK_DIR", "/tmp")
189195

196+
@pytest.fixture(autouse=True)
197+
def _mock_validate_weights_path(self) -> None:
198+
"""Avoid disk checks for fake model paths in fixtures."""
199+
with patch("vec_inf.client._helper.utils.validate_weights_path"):
200+
yield
201+
190202
@pytest.fixture
191203
def model_config(self) -> ModelConfig:
192204
"""Fixture providing a basic model configuration."""

tests/vec_inf/client/test_helper.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
class TestModelLauncher:
3333
"""Tests for the ModelLauncher class."""
3434

35+
@pytest.fixture(autouse=True)
36+
def _mock_validate_weights_path(self) -> None:
37+
"""Avoid disk checks for fake model paths in fixtures."""
38+
with patch("vec_inf.client._helper.utils.validate_weights_path"):
39+
yield
40+
3541
@pytest.fixture
3642
def model_config(self) -> ModelConfig:
3743
"""Fixture providing a basic model configuration for tests."""
@@ -385,6 +391,12 @@ def test_launch_with_sglang_engine(
385391
class TestBatchModelLauncher:
386392
"""Tests for the BatchModelLauncher class."""
387393

394+
@pytest.fixture(autouse=True)
395+
def _mock_validate_weights_path(self) -> None:
396+
"""Avoid disk checks for fake model paths in fixtures."""
397+
with patch("vec_inf.client._helper.utils.validate_weights_path"):
398+
yield
399+
388400
@pytest.fixture
389401
def batch_model_configs(self) -> list[ModelConfig]:
390402
"""Fixture providing batch model configurations for tests."""

tests/vec_inf/client/test_slurm_script_generator.py

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
)
1313

1414

15-
@pytest.fixture(autouse=True)
16-
def patch_model_weights_exists(monkeypatch):
17-
"""Ensure model weights directory existence checks default to True."""
18-
monkeypatch.setattr(
19-
"vec_inf.client._slurm_script_generator.Path.exists", lambda self: True
20-
)
21-
22-
2315
class TestSlurmScriptGenerator:
2416
"""Tests for SlurmScriptGenerator class."""
2517

@@ -123,7 +115,7 @@ def test_init_singularity(self, singularity_params):
123115
assert generator.params == singularity_params
124116
assert generator.use_container
125117
assert not generator.is_multinode
126-
assert generator.additional_binds == ",/scratch:/scratch,/data:/data"
118+
assert generator.additional_binds == "/scratch:/scratch,/data:/data"
127119
assert generator.model_weights_path == "/path/to/model_weights/test-model"
128120
assert (
129121
generator.env_str
@@ -195,18 +187,16 @@ def test_generate_server_setup_singularity(self, singularity_params):
195187
) # Remove module name since it's inconsistent between clusters
196188

197189
def test_generate_server_setup_singularity_no_weights(
198-
self, singularity_params, monkeypatch
190+
self, singularity_params
199191
):
200-
"""Test server setup when model weights don't exist."""
201-
monkeypatch.setattr(
202-
"vec_inf.client._slurm_script_generator.Path.exists",
203-
lambda self: False,
204-
)
192+
"""Test server setup when using hf_model (no local weights in bind path)."""
193+
params = singularity_params.copy()
194+
params["hf_model"] = "test-org/test-model"
205195

206-
generator = SlurmScriptGenerator(singularity_params)
196+
generator = SlurmScriptGenerator(params)
207197
setup = generator._generate_server_setup()
208198

209-
assert "ray stop" in setup
199+
assert "module load" in setup or "apptainer" in setup.lower()
210200
assert "/path/to/model_weights/test-model" not in setup
211201

212202
def test_generate_launch_cmd_venv(self, basic_params):
@@ -337,13 +327,8 @@ def test_generate_script_content_sglang(self, basic_params):
337327
assert "sglang.launch_server" in content
338328
assert "find_available_port" in content
339329

340-
def test_generate_launch_cmd_with_hf_model_override(
341-
self, basic_params, monkeypatch
342-
):
343-
"""Test launch command uses hf_model when local weights don't exist."""
344-
monkeypatch.setattr(
345-
"vec_inf.client._slurm_script_generator.Path.exists", lambda self: False
346-
)
330+
def test_generate_launch_cmd_with_hf_model_override(self, basic_params):
331+
"""Test launch command uses hf_model when specified."""
347332
params = basic_params.copy()
348333
params["hf_model"] = "meta-llama/Meta-Llama-3.1-8B-Instruct"
349334
generator = SlurmScriptGenerator(params)
@@ -361,20 +346,18 @@ def test_generate_launch_cmd_singularity(self, singularity_params):
361346
assert "source" not in launch_cmd
362347

363348
def test_generate_launch_cmd_singularity_no_local_weights(
364-
self, singularity_params, monkeypatch
349+
self, singularity_params
365350
):
366-
"""Test container launch when model weights directory is missing."""
367-
monkeypatch.setattr(
368-
"vec_inf.client._slurm_script_generator.Path.exists",
369-
lambda self: False,
370-
)
351+
"""Test container launch when using hf_model instead of local weights."""
352+
params = singularity_params.copy()
353+
params["hf_model"] = "test-org/test-model"
371354

372-
generator = SlurmScriptGenerator(singularity_params)
355+
generator = SlurmScriptGenerator(params)
373356
launch_cmd = generator._generate_launch_cmd()
374357

375358
assert "exec --nv" in launch_cmd
376-
assert "--bind /path/to/model_weights/test-model" not in launch_cmd
377-
assert "vllm serve test-model" in launch_cmd
359+
assert "vllm serve test-org/test-model" in launch_cmd
360+
assert "vllm serve /path/to/model_weights/test-model" not in launch_cmd
378361

379362
def test_generate_launch_cmd_boolean_args(self, basic_params):
380363
"""Test launch command with boolean vLLM arguments."""
@@ -522,11 +505,11 @@ def test_init_singularity(self, batch_singularity_params):
522505
assert generator.use_container
523506
assert (
524507
generator.params["models"]["model1"]["additional_binds"]
525-
== ",/scratch:/scratch,/data:/data"
508+
== "/scratch:/scratch,/data:/data"
526509
)
527510
assert (
528511
generator.params["models"]["model2"]["additional_binds"]
529-
== ",/scratch:/scratch,/data:/data"
512+
== "/scratch:/scratch,/data:/data"
530513
)
531514

532515
def test_init_singularity_no_bind(self, batch_params):
@@ -571,12 +554,9 @@ def test_generate_model_launch_script_basic(
571554
@patch("pathlib.Path.touch")
572555
@patch("pathlib.Path.write_text")
573556
def test_generate_model_launch_script_with_hf_model_override(
574-
self, mock_write_text, mock_touch, batch_params, monkeypatch
557+
self, mock_write_text, mock_touch, batch_params
575558
):
576-
"""Test batch launch script uses hf_model when local weights don't exist."""
577-
monkeypatch.setattr(
578-
"vec_inf.client._slurm_script_generator.Path.exists", lambda self: False
579-
)
559+
"""Test batch launch script uses hf_model when specified."""
580560
params = batch_params.copy()
581561
params["models"] = {k: v.copy() for k, v in batch_params["models"].items()}
582562
params["models"]["model1"]["hf_model"] = "meta-llama/Meta-Llama-3.1-8B-Instruct"
@@ -604,20 +584,22 @@ def test_generate_model_launch_script_singularity(
604584
@patch("pathlib.Path.touch")
605585
@patch("pathlib.Path.write_text")
606586
def test_generate_model_launch_script_singularity_no_weights(
607-
self, mock_write_text, mock_touch, batch_singularity_params, monkeypatch
587+
self, mock_write_text, mock_touch, batch_singularity_params
608588
):
609-
"""Test batch model launch script when model weights don't exist."""
610-
monkeypatch.setattr(
611-
"vec_inf.client._slurm_script_generator.Path.exists",
612-
lambda self: False,
613-
)
589+
"""Test batch model launch script when using hf_model (no local weights)."""
590+
params = batch_singularity_params.copy()
591+
params["models"] = {
592+
k: v.copy() for k, v in batch_singularity_params["models"].items()
593+
}
594+
params["models"]["model1"]["hf_model"] = "test-org/model1"
614595

615-
generator = BatchSlurmScriptGenerator(batch_singularity_params)
596+
generator = BatchSlurmScriptGenerator(params)
616597
script_path = generator._generate_model_launch_script("model1")
617598

618599
assert script_path.name == "launch_model1.sh"
619600
call_args = mock_write_text.call_args[0][0]
620601
assert "/path/to/model_weights/model1" not in call_args
602+
assert "vllm serve test-org/model1" in call_args
621603

622604
@patch("vec_inf.client._slurm_script_generator.datetime")
623605
@patch("pathlib.Path.touch")

0 commit comments

Comments
 (0)