wildedge-python icon indicating copy to clipboard operation
wildedge-python copied to clipboard

transformers pipelines with generator or dataset inputs record events before inference runs

Open piotrekno1 opened this issue 1 month ago • 0 comments

What happens

When a transformers pipeline is called with a generator, a dataset or another lazy input, Pipeline.__call__ returns a PipelineIterator, and inference runs only as that iterator is consumed. The integration's Pipeline.__call__ patch records its success event when __call__ returns, before any inference has run. Then each consumed item runs the model outside the tracked call, so the model's forward hooks record one event per item.

Checked with transformers 5.20.1 and the fix from #77:

Call Events
clf("hello world") 1 pipeline event (correct)
out = clf(x for x in ["hello", "world"]) 1 pipeline event right away: no input_meta, near-zero duration, before any inference
list(out) 2 more model events, one per item

So two inputs produce three events, and the first one's duration and success don't describe any real inference.

Expected

For a lazy input, record one event per item as the iterator is consumed (with its duration and output), or one event when it's exhausted. No event should be recorded when __call__ returns the iterator. The model's forward hooks should stay quiet while the iterator is being consumed.

Notes

  • This predates #77; #77 only stops eager calls from being counted twice.
  • Pipeline.__call__ decides this based on input type (types.GeneratorType, Dataset, KeyDataset), so the patch can tell from the return value: a PipelineIterator or another iterator instead of a list or dict.

🤖 Generated with Claude Code

piotrekno1 avatar Oct 20 '26 15:10 piotrekno1