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

Add cleanup_torchscript_cache to test_quantize_conformance.py #2171

Merged

Conversation

AlexanderDokuchaev
Copy link
Collaborator

@AlexanderDokuchaev AlexanderDokuchaev commented Oct 4, 2023

Changes

Add cleanup_torchscript_cache function to test_quantize_conformance.py

Reason for changes

After run torch.jit.trace in convert_model, PyTorch does not clear the trace cache automatically.

Same function in torch test and openvino notebok:
https://github.com/pytorch/pytorch/blob/main/torch/testing/_internal/jit_utils.py#L59
https://github.com/openvinotoolkit/openvino_notebooks/blob/1932d4b4e99116bdedaa620c9dc92069fbb1f05e/notebooks/236-stable-diffusion-v2/implementation/conversion_helper_utils.py#L8

@AlexanderDokuchaev AlexanderDokuchaev requested a review from a team as a code owner October 4, 2023 09:15
@github-actions github-actions bot added the NNCF PTQ Pull requests that updates NNCF PTQ label Oct 4, 2023
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #2171 (c7deb33) into develop (bfefa7c) will decrease coverage by 0.03%.
Report is 7 commits behind head on develop.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2171      +/-   ##
===========================================
- Coverage    36.12%   36.09%   -0.03%     
===========================================
  Files          478      480       +2     
  Lines        42711    43243     +532     
===========================================
+ Hits         15429    15610     +181     
- Misses       27282    27633     +351     

see 43 files with indirect coverage changes

@AlexanderDokuchaev AlexanderDokuchaev changed the title Run ptq tests in subprocess Add cleanup_torchscript_cache to test_quantize_conformance.py Oct 5, 2023
@AlexanderDokuchaev
Copy link
Collaborator Author

AlexanderDokuchaev commented Oct 5, 2023

Reproducer:

import openvino as ov
import timm
import torch

dummy_tensor = torch.rand([1, 3, 224, 224])

def cleanup_torchscript_cache():
    torch._C._jit_clear_class_registry()
    torch.jit._recursive.concrete_type_store = torch.jit._recursive.ConcreteTypeStore()
    torch.jit._state._clear_class_state()

for i in range(10):
    timm_model = timm.create_model("hrnet_w18", num_classes=1000, in_chans=3, pretrained=True, checkpoint_path="")
    ov_model = ov.convert_model(timm_model, example_input=dummy_tensor)
    # cleanup_torchscript_cache()

Run script with mprof

pip install memory_profiler
mprof run --python python3 mem.py
mprof plot -o plot.png

Without cleanup_torchscript_cache:
image
With cleanup_torchscript_cache:
image

In test_quantize_conformance.py result looks like:

Model RAM MiB
hf/bert-base-uncased 2198
timm/crossvit_9_240 4778
timm/darknet53 5264
timm/deit3_small_patch16_224 5259
timm/dla34 5345
timm/dpn68 5339
timm/efficientnet_b0 5476
timm/efficientnet_lite0 5626
timm/hrnet_w18 6224
timm/inception_resnet_v2 7009
timm/levit_128 7294
timm/mobilenetv2_050 7289
timm/mobilenetv3_small_050 7348
timm/regnetx_002 7482
timm/resnest14d 7631
timm/resnet18 7694
timm/swin_base_patch4_window7_224 8186
timm/tf_inception_v3 8440
timm/vgg11 8817
timm/visformer_small 8462
timm/wide_resnet50_2 8634

Copy link
Contributor

@vshampor vshampor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job tracking this down to actual source.

@alexsu52 alexsu52 merged commit a97fff9 into openvinotoolkit:develop Oct 9, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants