Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace progressbar with tqdm #3494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions Examples/onnx/utils/image_net_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"""
import logging

import progressbar
from tqdm import tqdm
import torch
import onnxruntime as ort

Expand Down Expand Up @@ -92,25 +92,19 @@ def evaluate(self, sess: ort.InferenceSession, iterations: int = None) -> float:
logger.info("Evaluating nn.Module for %d iterations with batch_size %d",
iterations, self._val_data_loader.batch_size)

batch_cntr = 1
with progressbar.ProgressBar(max_value=iterations) as progress_bar:
for input_data, target_data in self._val_data_loader:
for i, (input_data, target_data) in tqdm(enumerate(self._val_data_loader), total=10):
if i == 10:
break

inputs_batch = input_data.numpy()
inputs_batch = input_data.numpy()

predicted_batch = sess.run(None, {input_name : inputs_batch})[0]
predicted_batch = sess.run(None, {input_name : inputs_batch})[0]

batch_avg_top_1_5 = accuracy(output=torch.from_numpy(predicted_batch), target=target_data,
topk=(1, 5))
batch_avg_top_1_5 = accuracy(output=torch.from_numpy(predicted_batch), target=target_data,
topk=(1, 5))

acc_top1 += batch_avg_top_1_5[0].item()
acc_top5 += batch_avg_top_1_5[1].item()

progress_bar.update(batch_cntr)

batch_cntr += 1
if batch_cntr > iterations:
break
acc_top1 += batch_avg_top_1_5[0].item()
acc_top5 += batch_avg_top_1_5[1].item()

acc_top1 /= iterations
acc_top5 /= iterations
Expand Down
18 changes: 8 additions & 10 deletions Examples/torch/quantization/qat_range_learning_ddp_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import socket
import argparse

import progressbar
from tqdm import tqdm
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
Expand Down Expand Up @@ -129,15 +129,13 @@ def evaluate_quant(model, _):
model.to(device)
model.eval()

with progressbar.ProgressBar(max_value=100) as progress_bar:
with torch.no_grad():
for i, (images, _) in enumerate(val_loader):
images = images.to(device)
# compute output
_ = model(images)
progress_bar.update(i)
if i == 100:
break
with torch.no_grad():
for i, (images, _) in tqdm(enumerate(val_loader), total=100):
images = images.to(device)
# compute output
_ = model(images)
if i == 100:
break

return evaluate_quant

Expand Down
30 changes: 12 additions & 18 deletions Examples/torch/utils/image_net_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"""
import logging

import progressbar
from tqdm import tqdm
import torch
from torch import nn

Expand Down Expand Up @@ -104,27 +104,21 @@ def evaluate(self, model: nn.Module, iterations: int = None, use_cuda: bool = Fa
model = model.to(device)
model = model.eval()

batch_cntr = 1
with progressbar.ProgressBar(max_value=iterations) as progress_bar:
with torch.no_grad():
for input_data, target_data in self._val_data_loader:
with torch.no_grad():
for i, (input_data, target_data) in tqdm(enumerate(self._val_data_loader), total=iterations):
if i == iterations:
break

inputs_batch = input_data.to(device)
target_batch = target_data.to(device)
inputs_batch = input_data.to(device)
target_batch = target_data.to(device)

predicted_batch = model(inputs_batch)
predicted_batch = model(inputs_batch)

batch_avg_top_1_5 = accuracy(output=predicted_batch, target=target_batch,
topk=(1, 5))
batch_avg_top_1_5 = accuracy(output=predicted_batch, target=target_batch,
topk=(1, 5))

acc_top1 += batch_avg_top_1_5[0].item()
acc_top5 += batch_avg_top_1_5[1].item()

progress_bar.update(batch_cntr)

batch_cntr += 1
if batch_cntr > iterations:
break
acc_top1 += batch_avg_top_1_5[0].item()
acc_top5 += batch_avg_top_1_5[1].item()

acc_top1 /= iterations
acc_top5 /= iterations
Expand Down
57 changes: 26 additions & 31 deletions Examples/torch/utils/image_net_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"""
import logging

import progressbar
from tqdm import tqdm
import torch
from torch import nn, optim

Expand Down Expand Up @@ -103,36 +103,31 @@ def _train_loop(self, model: nn.Module, criterion: torch.nn.modules.loss, optimi
model.train()

avg_loss = 0.0
curr_iter = 1

with progressbar.ProgressBar(max_value=max_iterations) as progress_bar:
for images, target in self._train_loader:
images = images.to(device)
target = target.to(device)

# compute model output
output = model(images)
loss = criterion(output, target)
avg_loss += loss.item()

# compute gradient and do SGD step
optimizer.zero_grad()
loss.backward()
optimizer.step()

progress_bar.update(curr_iter)

if curr_iter % debug_steps == 0:
eval_accuracy = self._evaluator.evaluate(model, use_cuda=use_cuda)
logger.info('Epoch #%d/%d: iteration #%d/%d: Global Avg Loss=%f, Eval Accuracy=%f',
current_epoch, max_epochs, curr_iter, max_iterations,
avg_loss / curr_iter, eval_accuracy)
# switch to training mode after evaluation
model.train()

curr_iter += 1
if curr_iter > max_iterations:
break

for i, (images, target) in tqdm(enumerate(self._train_loader), total=max_iterations):
if i == max_iterations:
break

images = images.to(device)
target = target.to(device)

# compute model output
output = model(images)
loss = criterion(output, target)
avg_loss += loss.item()

# compute gradient and do SGD step
optimizer.zero_grad()
loss.backward()
optimizer.step()

if (i+1) % debug_steps == 0:
eval_accuracy = self._evaluator.evaluate(model, use_cuda=use_cuda)
logger.info('Epoch #%d/%d: iteration #%d/%d: Global Avg Loss=%f, Eval Accuracy=%f',
current_epoch, max_epochs, curr_iter, max_iterations,
avg_loss / curr_iter, eval_accuracy)
# switch to training mode after evaluation
model.train()

eval_accuracy = self._evaluator.evaluate(model, use_cuda=use_cuda)
print("eval : ", eval_accuracy)
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.onnx-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.onnx-gpu
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.tf-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.19.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.tf-gpu
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.19.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.tf-torch-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
# protobuf==3.20.1 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.torch-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.torch-cpu-pt113
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.torch-gpu
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/Dockerfile.torch-gpu-pt113
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/fast-release/Dockerfile.torch-gpu-pt21-py310
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
1 change: 0 additions & 1 deletion Jenkins/fast-release/Dockerfile.torch-gpu-pt21-py38
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ RUN python3 -m pip --no-cache-dir install \
piccolo-theme \
Pillow==9.3.0 \
pluggy==0.12.0 \
progressbar2 \
protobuf==3.20.2 \
psutil \
ptflops \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ onnx==1.14.1
onnxsim
osqp
pandas==1.5.3
progressbar2
protobuf==3.20.2
psutil
pybind11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ onnx==1.14.1
onnxsim
osqp
pandas==1.5.3
progressbar2
protobuf==3.20.2
psutil
pybind11
Expand Down
1 change: 0 additions & 1 deletion packaging/dependencies/reqs_pip_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hvplot==0.9.2
Jinja2==3.0.3
jsonschema
osqp
progressbar2
pybind11
PyYAML
scikit-learn==1.1.3
Expand Down
Loading