Skip to content

Commit

Permalink
fixing import bug and gating by torch version (#88)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #88

caused #87 when trying to migrate fvcore to ao, this fixes by gating before importing

Reviewed By: ppwwyyxx

Differential Revision: D31706627

fbshipit-source-id: f30d950c89ef86e4f43a10ef568bd5d3c9f362e9
  • Loading branch information
HDCharles authored and facebook-github-bot committed Oct 18, 2021
1 parent 4a39fce commit 2454c6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion fvcore/common/checkpoint.py
Expand Up @@ -18,7 +18,11 @@
if TORCH_VERSION >= (1, 11):
from torch.ao import quantization
from torch.ao.quantization import ObserverBase, FakeQuantizeBase
else:
elif (
TORCH_VERSION >= (1, 8)
and hasattr(torch.quantization, "FakeQuantizeBase")
and hasattr(torch.quantization, "ObserverBase")
):
from torch import quantization
from torch.quantization import ObserverBase, FakeQuantizeBase

Expand Down
7 changes: 6 additions & 1 deletion tests/test_checkpoint.py
Expand Up @@ -15,6 +15,7 @@
from fvcore.common.checkpoint import Checkpointer, PeriodicCheckpointer
from torch import nn


TORCH_VERSION: Tuple[int, ...] = tuple(int(x) for x in torch.__version__.split(".")[:2])
if TORCH_VERSION >= (1, 11):
from torch.ao import quantization
Expand All @@ -24,7 +25,11 @@
disable_observer,
enable_fake_quant,
)
else:
elif (
TORCH_VERSION >= (1, 8)
and hasattr(torch.quantization, "FakeQuantizeBase")
and hasattr(torch.quantization, "ObserverBase")
):
from torch import quantization
from torch.quantization import (
get_default_qat_qconfig,
Expand Down

0 comments on commit 2454c6e

Please sign in to comment.