openvinotoolkit / nncf

Neural Network Compression Framework for enhanced OpenVINOā„¢ inference
Apache License 2.0
917 stars 228 forks source link

How to use custom dataloder in QAT? #2982

Open huangqiu15444 opened 6 days ago

huangqiu15444 commented 6 days ago

šŸ› Describe the bug

TypeError: conv2d() received an invalid combination of arguments - got (dict, Parameter, Parameter, tuple, tuple, tuple, int), but expected one of:

Is there is way to use a custom dataloader in the same way as ā€œdef transform_fn(dataitem): images, = data_item return imagesā€?

Environment

about-time==4.2.1 albumentations==1.3.1 alive-progress==3.1.5 attrs==24.2.0 autograd==1.7.0 certifi==2024.8.30 chardet==5.2.0 charset-normalizer==3.3.2 cma==3.2.2 colorama==0.4.6 coloredlogs==15.0.1 contourpy==1.1.1 cycler==0.12.1 Deprecated==1.2.14 dill==0.3.8 einops==0.8.0 filelock==3.15.4 flatbuffers==24.3.25 fonttools==4.53.1 fsspec==2024.6.1 grapheme==0.6.0 humanfriendly==10.0 idna==3.8 imageio==2.35.1 importlib_resources==6.4.4 Jinja2==3.1.4 joblib==1.4.2 jsonschema==4.23.0 jsonschema-specifications==2023.12.1 jstyleson==0.0.2 kiwisolver==1.4.5 lazy_loader==0.4 lightning-utilities==0.11.6 markdown-it-py==3.0.0 MarkupSafe==2.1.5 matplotlib==3.7.5 mdurl==0.1.2 mpmath==1.3.0 natsort==8.4.0 networkx==3.1 ninja==1.11.1.1 nncf==2.12.0 numpy==1.24.4 onnx==1.16.2 onnxoptimizer==0.3.13 onnxruntime==1.19.0 onnxsim==0.4.36 opencv-python==4.10.0.84 opencv-python-headless==4.10.0.84 openvino==2024.3.0 openvino-telemetry==2024.1.0 packaging==24.1 pandas==2.0.3 pillow==10.4.0 pkgutil_resolve_name==1.3.10 protobuf==5.28.0 psutil==6.0.0 pyclipper==1.3.0.post5 pydot==2.0.0 Pygments==2.18.0 pymoo==0.6.1.2 pyparsing==3.1.4 pyreadline3==3.4.1 python-dateutil==2.9.0.post0 pytz==2024.1 PyWavelets==1.4.1 PyYAML==6.0.2 qudida==0.0.4 referencing==0.35.1 requests==2.32.3 rich==13.8.0 rpds-py==0.20.0 scikit-image==0.21.0 scikit-learn==1.3.2 scipy==1.10.1 seaborn==0.13.2 shapely==2.0.6 six==1.16.0 sympy==1.13.2 tabulate==0.9.0 tensorboardX==2.6.2.2 threadpoolctl==3.5.0 tifffile==2023.7.10 torch==2.2.2+cu121 torchaudio==2.2.2+cu121 torchmetrics==1.4.1 torchsummary==1.5.1 torchvision==0.17.2+cu121 tqdm==4.66.5 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 wrapt==1.16.0 zipp==3.20.1

Minimal Reproducible Example

nncf_config = NNCFConfig.from_json("int8_per_tensor.json") nncf_config = register_default_init_args(nncf_config, self.train_loader) compression_ctrl, quantized_model = create_compressed_model(self.model, nncf_config)

Are you going to submit a PR?

alexsu52 commented 5 days ago

Hello @huangqiu15444,

create_compressed_model will be deprecated in the next release. Please use nncf.quantize for QAT. Here is example: https://github.com/openvinotoolkit/nncf/tree/develop/examples/quantization_aware_training/torch/resnet18

huangqiu15444 commented 5 days ago

Hello @huangqiu15444,

create_compressed_model will be deprecated in the next release. Please use nncf.quantize for QAT. Here is example: https://github.com/openvinotoolkit/nncf/tree/develop/examples/quantization_aware_training/torch/resnet18

Thank you for your reply. I would like to know how to configure parameters such as ā€˜per_channelā€˜ in nncf.quantize(model, quantization_dataset).

alexsu52 commented 4 days ago

You can manage quantization parameters via advanced_parameters argument of nncf.quantize: https://openvinotoolkit.github.io/nncf/autoapi/nncf/quantization/advanced_parameters/index.html