TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

pytorch-quantization example is incompatible with latest torchvision version

Open spinzello opened this issue 2 years ago • 5 comments

Description

I'm trying to run the following pytorch-quantization example: tools/pytorch-quantization/examples/calibrate_quant_resnet50.ipynb

The notebook "manually" imports functions from torchvision (without version reference), which seem to have been updated since, thereby leading to an error when running the example.

Specifically, in the "Create data loader" section:

_args = collections.namedtuple('mock_args', ['model', 'distributed', 'cache_dataset'])
dataset, dataset_test, train_sampler, test_sampler = load_data(traindir, valdir, _args(model='resnet50', distributed=False, cache_dataset=False))

I get the following error using the function load_data: 'mock_args' object has no attribute 'val_resize_size'

It seems that the namedtuple _args is expected to have more attributes. I checked out the load_data function and it expects many more attributes besides 'val_resize_size'.

Unless I imported the wrong function or forgot to run another code-block, I'd guess that the example needs to be updated to be compatible with the current torchvision functions. At the very least, the example could point to the version that was used.

This example is referenced in an Nvidia blog. Keeping this up-to-date might help others stumbling upon this.

Environment

TensorRT Version: 8.6.1

Operating System: Windows

Python Version: 3.9.12

PyTorch Version: 2.1.1+cu121

Steps To Reproduce

Run tools/pytorch-quantization/examples/calibrate_quant_resnet50.ipynb

spinzello avatar Nov 27 '23 15:11 spinzello

@ttyio ^ ^

zerollzeng avatar Nov 28 '23 14:11 zerollzeng

Thanks @SebastianPinzello , we will fixing this!

ttyio avatar Dec 05 '23 18:12 ttyio

Thanks @SebastianPinzello , we will fixing this!

Your work is great! When will this bug be fixed? By the way, will pytorch-quantization add more examples?

Zhang-Wen-chao avatar Apr 19 '24 02:04 Zhang-Wen-chao

vision tag v0.9.0 is ok.

Zhang-Wen-chao avatar Apr 20 '24 06:04 Zhang-Wen-chao

It seems that things are moving quite fast in this area and the current modus operandi is to create new tools instead of building on existing ones. Don't expect too much support here. For anyone looking into quantization stuff, the TensorRT Model Optimizer seems to be quite fresh. The section on PyTorch is refactored based on pytorch_quantization. You may find more going on there. Good luck!

TensorRT Tools Overview

Model Optimizer Documentation

Model Optimizer GitHub

spinzello avatar May 28 '24 12:05 spinzello