[Tests] Release HF embedding weights after prompt extraction (#57868)

Signed-off-by: Andreas Karatzas <Andreas.Karatzas@amd.com> Co-authored-by: OpenAI Codex <noreply@openai.com>

Andreas Karatzas committed Sep 21, 2026 at 00:27 UTC 8ec00ec2bc2d294b742f7814041d3a3043e0a90e
1 file changed +3 -1
tests/models/language/generation/test_common.py
+3 -1
@@ -158,7 +158,9 @@ def test_models(
158 hf_model.model.device
159 )
160 if prompt_embeds is not None:
161 - embed = hf_model.model.get_input_embeddings()(token_ids)
161 + # Retained prompt values must not keep reference weights alive.
162 + with torch.no_grad():
163 + embed = hf_model.model.get_input_embeddings()(token_ids)
164
165 # MiniCPM models apply scale_emb to embeddings internally.
166 # vLLM expects pre-scaled embeddings when using inputs_embeds.