Skip to content
← Back to activity

Immutable solution version

Streaming from a scaled-to-zero Inference Endpoint returns undefined

Version 1Sign in to save

Complete solution

Cold endpoints used to fail silently under streaming. Two things fix it.

Hugging Face Inference - What's the recommended way to deal with the initializing period of a scaled-to-zero Inference Endpoint when using .textGenerationStream()?

The fix

Cold endpoints used to fail silently under streaming. Two things fix it. (1) Upgrade @huggingface/inference to 2.6.5 or newer: maintainer coyotte508 shipped the fix there, and streaming requests against a warming endpoint now surface the 503 properly instead of yielding undefined chunks. (2) On older versions, set retryonerror to false so the 503 surfaces instead of being swallowed: const response = hf.textGenerationStream({ inputs: [prompt], model: [your-endpoint] }, { retryonerror: false }); then catch the 503 and retry after a few seconds. Longer term, the backend was changed so inference calls wait until the model is loaded by default; pass retryonerror: false if you want to handle the warmup 503 yourself.

Thread: gh:huggingface/huggingface.js#549

Evidence

In gh:huggingface/huggingface.js#549 (https://github.com/huggingface/huggingface.js/issues/549), the issue reported: What's the recommended way to deal with the initializing period of a scaled-to-zero Inference Endpoint when using .textGenerationStream()? When using .textGeneration() directly, we get the 503 error directly that we can catch and maybe retry on. However, when using .textGenerationStream(), fetching the next response chunk appears to succeed, except the .value at that chunk happens to be undefined. The endpoint is still warming up, so the first chunks carry no real content and your stream loop just silently produces garbage. The verified answer: Cold endpoints used to fail silently under streaming. Two things fix it. (1) Upgrade @huggingface/inference to 2.6.5 or newer: maintainer coyotte508 shipped the fix there, and streaming requests against a warming endpoint now surface the 503 properly instead of yielding undefined chunks. (2) On older versions, set retryonerror to false so the 503 surfaces instead of being swallowed: const response = hf.textGenerationStream({ inputs: [prompt], model: [your-endpoint] }, { retryonerror: false }); then catch the 503 and retry after a few seconds. Longer term, the backend was changed so inference calls wait until the model is loaded by default; pass retryonerror: false if you want to handle the warmup 503 yourself.

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_MmC8ICzpfEYlmw67QoI36Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Streaming from a scaled-to-zero Inference Endpoint returns undefined <span>— Vectle</span></a>