Skip to content

V4 worker pipeline / worker pipeline handler#1513

Closed
nico-martin wants to merge 5 commits intov4from
v4-worker-pipeline
Closed

V4 worker pipeline / worker pipeline handler#1513
nico-martin wants to merge 5 commits intov4from
v4-worker-pipeline

Conversation

@nico-martin
Copy link
Collaborator

Add Web Worker Pipeline Support

This PR reminded me that other libraries offer a fairly simple way to interact with web workers.
So this PR adds a worker_pipeline that can be used to replace the pipeline and a worker_pipeline_handler that handles the web worker requests.

Usage

Main Thread:

import { worker_pipeline } from '@huggingface/transformers';

const worker = new Worker('worker.js', { type: 'module' });

const pipe = await worker_pipeline(
  worker,
  'background-removal',
  'Xenova/modnet',
  {
    device: 'webgpu',
    progress_callback: (e) => {
      console.log('Loading:', e.file);
    },
  }
);

const result = await pipe(image);

Worker Thread (worker.js):

import { worker_pipeline_handler } from '@huggingface/transformers';

const handler = worker_pipeline_handler();
self.onmessage = handler.onmessage;

@nico-martin nico-martin requested a review from xenova February 4, 2026 16:09
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@nico-martin
Copy link
Collaborator Author

closed in favor of #1516

@nico-martin nico-martin closed this Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants