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-
2315class 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