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

[Quant] Add FX support in quantization examples #5797

Closed
wants to merge 8 commits into from

Commits on Apr 10, 2022

  1. [Quant] Add FX support in quantization examples

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well. TODO: provide accuracy comparison.
    
    Test Plan:
    
    python train_quantization.py
      --device='cpu'
      --post-training-quantize
      --backend='fbgemm'
      --model='$MODEL'
    
    model: $MODEL is one of googlenet, inception_v3, resnet18, resnet50,
    resnext101_32x8d, shufflenet_v2_x0_5 and shufflenet_v2_x1_0
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 10, 2022
    Configuration menu
    Copy the full SHA
    beff9a2 View commit details
    Browse the repository at this point in the history

Commits on Apr 12, 2022

  1. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well. TODO: provide accuracy comparison.
    
    Test Plan:
    
    python train_quantization.py
      --device='cpu'
      --post-training-quantize
      --backend='fbgemm'
      --model='$MODEL'
    
    model: $MODEL is one of googlenet, inception_v3, resnet18, resnet50,
    resnext101_32x8d, shufflenet_v2_x0_5 and shufflenet_v2_x1_0
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 12, 2022
    Configuration menu
    Copy the full SHA
    d5373ca View commit details
    Browse the repository at this point in the history
  2. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well. TODO: provide accuracy comparison.
    
    Test Plan:
    
    python train_quantization.py
      --device='cpu'
      --post-training-quantize
      --backend='fbgemm'
      --model='$MODEL'
    
    model: $MODEL is one of googlenet, inception_v3, resnet18, resnet50,
    resnext101_32x8d, shufflenet_v2_x0_5 and shufflenet_v2_x1_0
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 12, 2022
    Configuration menu
    Copy the full SHA
    1e39944 View commit details
    Browse the repository at this point in the history

Commits on Apr 13, 2022

  1. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well. TODO: provide accuracy comparison.
    
    Test Plan:
    
    python train_quantization.py
      --device='cpu'
      --post-training-quantize
      --backend='fbgemm'
      --model='$MODEL'
    
    model: $MODEL is one of googlenet, inception_v3, resnet18, resnet50,
    resnext101_32x8d, shufflenet_v2_x0_5 and shufflenet_v2_x1_0
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 13, 2022
    Configuration menu
    Copy the full SHA
    0a4a7bf View commit details
    Browse the repository at this point in the history
  2. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well.
    
    Test Plan:
    
    ```
    # MODEL is one of googlenet, inception_v3, resnet18, resnet50, resnext101_32x8d,
    # shufflenet_v2_x0_5, shufflenet_v2_x1_0, mobilenet_v2, mobilenet_v3_large
    
    # eager
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm" --model="$MODEL"
    --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # fx
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm" --model="$MODEL"
    --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # eager QAT (mobilenet only)
    python train_quantization.py --device="cuda" --backend="fbgemm" --model="$MODEL" --epochs=10
    --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # fx QAT (mobilenet only)
    python train_quantization.py --device="cuda" --backend="fbgemm" --model="$MODEL" --epochs=10
    --weights="IMAGENET1K_V1" --quantization-workflow-type="fx_graph_mode_quantization"
    ```
    
    Results:
    - "Before" column refers to accuracies reported [here](https://github.com/pytorch/vision/blob/main/docs/source/models.rst#quantized-models)
    - TODO: Add results for QAT mobilenet after it's done
    
    <img width="641" alt="Screen Shot 2022-04-12 at 10 58 01 PM" src="https://user-images.githubusercontent.com/2133137/163091177-e1c1c666-c3f7-40c3-8866-c0743c264721.png">
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 13, 2022
    Configuration menu
    Copy the full SHA
    2475285 View commit details
    Browse the repository at this point in the history

Commits on Apr 14, 2022

  1. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well.
    
    Test Plan:
    
    ```
    # ==================== PTQ ====================
    # MODEL is one of googlenet, inception_v3, resnet18, resnet50, resnext101_32x8d,
    # shufflenet_v2_x0_5, shufflenet_v2_x1_0
    
    # eager
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # fx
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # ==================== QAT ====================
    # mobilenet_v2 eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v2 fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    
    # mobilenet_v3_large eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v3_large fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    ```
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 14, 2022
    Configuration menu
    Copy the full SHA
    a84092a View commit details
    Browse the repository at this point in the history

Commits on Apr 21, 2022

  1. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well.
    
    Test Plan:
    
    ```
    # ==================== PTQ ====================
    # MODEL is one of googlenet, inception_v3, resnet18, resnet50, resnext101_32x8d,
    # shufflenet_v2_x0_5, shufflenet_v2_x1_0
    
    # eager
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # fx
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # ==================== QAT ====================
    # mobilenet_v2 eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v2 fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    
    # mobilenet_v3_large eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v3_large fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    ```
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 21, 2022
    Configuration menu
    Copy the full SHA
    4f4eb69 View commit details
    Browse the repository at this point in the history

Commits on Apr 22, 2022

  1. Update on "[Quant] Add FX support in quantization examples"

    Summary: Previously, the quantization examples use only eager
    mode quantization. This commit adds support for FX mode
    quantization as well.
    
    Test Plan:
    
    ```
    # ==================== PTQ ====================
    # MODEL is one of googlenet, inception_v3, resnet18, resnet50, resnext101_32x8d,
    # shufflenet_v2_x0_5, shufflenet_v2_x1_0
    
    # eager
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # fx
    python train_quantization.py --device="cpu" --post-training-quantize --backend="fbgemm"\
      --model="$MODEL" --weights="IMAGENET1K_V1" --quantization-workflow-type="eager_mode_quantization"
    
    # ==================== QAT ====================
    # mobilenet_v2 eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v2 fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v2"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.0001 --weight-decay=0.0001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    
    # mobilenet_v3_large eager
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="eager_mode_quantization"
    
    # mobilenet_v3_large fx
    python train_quantization.py --device="cuda" --backend="qnnpack" --model="mobilenet_v3_large"\
      --epochs=10 --workers=64 --weights="IMAGENET1K_V1" --lr=0.001 --weight-decay=0.00001\
      --quantization-workflow-type="fx_graph_mode_quantization"
    ```
    
    <img width="638" alt="Screen Shot 2022-04-21 at 8 33 41 PM" src="https://user-images.githubusercontent.com/2133137/164572469-5848c86b-0813-42f6-bcb7-0298ff4bb25b.png">
    
    Reviewers: jerryzh168, vkuzo
    
    Subscribers: jerryzh168, vkuzo
    
    [ghstack-poisoned]
    andrewor14 committed Apr 22, 2022
    Configuration menu
    Copy the full SHA
    9978cb0 View commit details
    Browse the repository at this point in the history