-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.x SQ autotune supports calib_func w/ capture input (#1821)
Signed-off-by: Cheng, Zixuan <[email protected]>
- Loading branch information
1 parent
7120dd4
commit 5dafe5f
Showing
3 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import copy | ||
|
||
import pytest | ||
import torch | ||
|
||
|
||
class Model(torch.nn.Module): | ||
device = torch.device("cpu") | ||
|
||
def __init__(self): | ||
super(Model, self).__init__() | ||
self.fc1 = torch.nn.Linear(3, 4) | ||
self.fc2 = torch.nn.Linear(4, 3) | ||
|
||
def forward(self, x): | ||
out = self.fc1(x) | ||
out = self.fc2(out) | ||
return out | ||
|
||
|
||
model = Model() | ||
|
||
|
||
def test_captured_dataloader(): | ||
from neural_compressor.torch.algorithms.smooth_quant import build_captured_dataloader | ||
|
||
fp32_model = copy.deepcopy(model) | ||
|
||
def run_fn(model): | ||
for i in range(10): | ||
example_inputs = torch.randn([1, 3]) | ||
model(example_inputs) | ||
|
||
tmp_model, dataloader = build_captured_dataloader(fp32_model, run_fn, calib_num=32) | ||
assert tmp_model == fp32_model, "Model should be same after building dataloader. Please check." | ||
assert isinstance(dataloader.args_list[0][0], torch.Tensor), "Args list should contain tensors. Please check." | ||
assert not dataloader.kwargs_list[0], "Kwargs list should be empty. Please check." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters