# Progress bar for HF pipelines

**URL:** <https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498>\
**Category:** 🤗Transformers\
**Created:** [July 18, 2022, 8:01am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498 "2022-07-18T08:01:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![vblagoje](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/vblagoje/32/20818_2.png) [@vblagoje](https://discuss.huggingface.co/u/vblagoje)\
**Post date:** [July 18, 2022, 8:01am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/1 "2022-07-18T08:01:47Z")

</div>

Hello everyone,

Is there a way to attach progress bars to HF pipelines? For example, in summarization pipeline I often pass a dozen of texts and would love to indicate to user how many texts have been summarized so far.

TIA,  
Vladimir

---

<div class="post-metadata">

**Author:** ![merve](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/merve/32/49809_2.png) [@merve](https://discuss.huggingface.co/u/merve)\
**Post date:** [July 18, 2022, 3:57pm UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/2 "2022-07-18T15:57:29Z")

</div>

Hello Vladimir 👋

I saw [this feature request](https://github.com/huggingface/transformers/issues/14789) where @Narsil says if you make your examples into a Hugging Face Dataset you can see the progress, like below:

```auto
dataset = MyDataset()

for out in tqdm.tqdm(pipe(dataset)):
    print(out)

class ListDataset(Dataset):
     def __init__ (self, original_list)
        self.original_list = original_list

    def __len__ (self):
        return len(self.original_list)

    def __getitem__ (self, i):
        return self.original_list[i]

```

I don’t know of a way to do this without something like [tqdm](https://github.com/tqdm/tqdm). (note that it adds extra complexity on top of your inference) below is my code.

```auto
from tqdm import tqdm
from transformers import pipeline

generator = pipeline(task="text-generation")
examples = [
        "Three Rings for the Elven-kings under the sky, Seven for the Dwarf-lords in their halls of stone",
        "Nine for Mortal Men, doomed to die, One for the Dark Lord on his dark throne",
    ]
 
for i in tqdm(range(len(examples))):
    generator(examples)

```

Maybe @osanseviero knows a better way of doing this.

---

<div class="post-metadata">

**Author:** ![vblagoje](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/vblagoje/32/20818_2.png) [@vblagoje](https://discuss.huggingface.co/u/vblagoje)\
**Post date:** [July 18, 2022, 8:37pm UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/3 "2022-07-18T20:37:08Z")

</div>

Hey @merve , thanks a bunch. Here is a small example Colab [notebook](https://colab.research.google.com/drive/1_h8NvcIpoYvcOVOOyD25tkdkDix-0TIq?usp=sharing)

---

<div class="post-metadata">

**Author:** ![afriedman412](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/afriedman412/32/4661_2.png) [@afriedman412](https://discuss.huggingface.co/u/afriedman412)\
**Post date:** [August 21, 2022, 1:10am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/4 "2022-08-21T01:10:48Z")

</div>

I couldn’t get this to work … could it be because my pipeline has a tokenizer built-in?

```auto
tokenizer = partial(AutoTokenizer.from_pretrained("results_820/checkpoint-10000/"), truncation=True)

def preprocess_data(data):
    encoding = tokenizer(data['text'], truncation=True)
    return encoding

model = AutoModelForSequenceClassification.from_pretrained("results_820/checkpoint-10000/", num_labels=2)

pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)

validation_df = pd.read_csv("validation_set.csv")
validation_dataset = Dataset.from_pandas(validation_df)

for out in tqdm.tqdm(pipe(validation_dataset["text"])):
    print(out)

```

---

<div class="post-metadata">

**Author:** ![vblagoje](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/vblagoje/32/20818_2.png) [@vblagoje](https://discuss.huggingface.co/u/vblagoje)\
**Post date:** [August 24, 2022, 7:55am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/5 "2022-08-24T07:55:09Z")

</div>

@afriedman412, you need to wrap your data into the torch dataset, not the huggingface dataset.

---

<div class="post-metadata">

**Author:** ![BrunoSE](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@BrunoSE](https://discuss.huggingface.co/u/BrunoSE)\
**Post date:** [November 9, 2022, 9:54pm UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/6 "2022-11-09T21:54:00Z")

</div>

@vblagoje @afriedman412 I’m stuck in the same problem. I have a hugging face dataset where text example that I want to predict on has an id. (i.e. dataset[‘test’][index][‘text’]). I got this from a pandas dataframe. Could you guide me with an example of how to get a torch dataset? Thank you!

---

<div class="post-metadata">

**Author:** ![maiia-bocharova](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/maiia-bocharova/32/43850_2.png) [@maiia-bocharova](https://discuss.huggingface.co/u/maiia-bocharova)\
**Post date:** [December 22, 2022, 11:03am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/7 "2022-12-22T11:03:03Z")

</div>

One workaround which I used:

```auto
results = []
CHUNK_SIZE = 100
for chunk in tqdm(range(test_df.shape[0] // CHUNK_SIZE + 1)):
    descr = test_df[CHUNK_SIZE * chunk: (CHUNK_SIZE+1) * chunk]['description'].to_list()
    res = nlp(descr)
    results += res

```

---

<div class="post-metadata">

**Author:** ![907Resident](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/907resident/32/24749_2.png) [@907Resident](https://discuss.huggingface.co/u/907Resident)\
**Post date:** [June 3, 2023, 12:30am UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/8 "2023-06-03T00:30:57Z")

</div>

Nice, this comment by @Maiia was very helpful. Thanks, this helped me see a 140% difference in my execution time for my code.

Also, adding `device_map="auto"` to the `pipeline` object ensures that the code will take advantage of whatever hardware config you may have. At least, my experience thus far

---

<div class="post-metadata">

**Author:** ![ddefranza](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ddefranza/32/20763_2.png) [@ddefranza](https://discuss.huggingface.co/u/ddefranza)\
**Post date:** [October 30, 2023, 1:53pm UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/9 "2023-10-30T13:53:59Z")

</div>

This is very helpful and solved my problem getting a tqdm progress bar working with an existing pipeline as well. One note:

I think the calculation of the data range based on chunk and CHUNK\_SIZE is off. It should look something more like:

```auto
descr = test_df[(CHUNK_SIZE * chunk) : (CHUNK_SIZE * chunk) + CHUNK_SIZE]['description'].to_list()

```

Either way, thanks again @maiia-bocharova for the excellent template.

---

<div class="post-metadata">

**Author:** ![marctorsoc](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@marctorsoc](https://discuss.huggingface.co/u/marctorsoc)\
**Post date:** [December 24, 2023, 9:58pm UTC](https://discuss.huggingface.co/t/progress-bar-for-hf-pipelines/20498/10 "2023-12-24T21:58:24Z")

</div>

It could really be

```auto
descr = test_df[(CHUNK_SIZE * chunk) : CHUNK_SIZE * (chunk + 1)]['description'].to_list()

```

The problem was factorizing `chunk` rather than `CHUNK_SIZE`. Btw, it still complaints about not using a `Dataset`. If someone finds a way to get progressbar less hacky than this, please post it 🙂
