Skip to content

Commit fa1cbb7

Browse files
authored
fix(deploy): drop None tp_plan before HF from_pretrained (#771)
Signed-off-by: Pruthviraj Prakash <pruprakash@nvidia.com>
1 parent 4d5c837 commit fa1cbb7

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎nemo_deploy/llm/hf_deployable.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def _load(
130130
"""
131131
assert self.task is not None, "A task has to be given for the generation task."
132132

133+
if "tp_plan" in hf_kwargs and hf_kwargs["tp_plan"] is None:
134+
hf_kwargs.pop("tp_plan")
135+
133136
if self.task == "text-generation":
134137
self.model = AutoModelForCausalLM.from_pretrained(
135138
self.hf_model_id_path, torch_dtype=torch_dtype, device_map=device_map, **hf_kwargs

‎tests/unit_tests/deploy/test_hf_deployable.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,38 @@ def test_initialization_with_peft_model(self, mock_model, mock_tokenizer, mock_p
135135
)
136136
assert deployer.model == mock_peft_model.from_pretrained.return_value
137137

138+
def test_initialization_omits_tp_plan_when_none(self, mock_model, mock_tokenizer):
139+
"""A tp_plan of None is not forwarded to from_pretrained."""
140+
with (
141+
patch(
142+
"transformers.AutoModelForCausalLM.from_pretrained",
143+
return_value=mock_model,
144+
) as mock_from_pretrained,
145+
patch(
146+
"transformers.AutoTokenizer.from_pretrained",
147+
return_value=mock_tokenizer,
148+
),
149+
):
150+
HuggingFaceLLMDeploy(hf_model_id_path="test/model", task="text-generation", tp_plan=None)
151+
mock_from_pretrained.assert_called_once()
152+
assert "tp_plan" not in mock_from_pretrained.call_args.kwargs
153+
154+
def test_initialization_forwards_tp_plan_when_set(self, mock_model, mock_tokenizer):
155+
"""A non-None tp_plan is forwarded to from_pretrained."""
156+
with (
157+
patch(
158+
"transformers.AutoModelForCausalLM.from_pretrained",
159+
return_value=mock_model,
160+
) as mock_from_pretrained,
161+
patch(
162+
"transformers.AutoTokenizer.from_pretrained",
163+
return_value=mock_tokenizer,
164+
),
165+
):
166+
HuggingFaceLLMDeploy(hf_model_id_path="test/model", task="text-generation", tp_plan="auto")
167+
mock_from_pretrained.assert_called_once()
168+
assert mock_from_pretrained.call_args.kwargs["tp_plan"] == "auto"
169+
138170
def test_triton_input_output_config(self):
139171
deployer = HuggingFaceLLMDeploy(model=MagicMock(), tokenizer=MagicMock(), task="text-generation")
140172

0 commit comments

Comments
 (0)