-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into yi3/sdpa_group_quant
- Loading branch information
Showing
39 changed files
with
996 additions
and
525 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,44 @@ | ||
# Copyright (C) 2018-2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
#! [dataset] | ||
import nncf | ||
import torch | ||
|
||
calibration_loader = torch.utils.data.DataLoader(...) | ||
|
||
def transform_fn(data_item): | ||
images, _ = data_item | ||
return images | ||
|
||
calibration_dataset = nncf.Dataset(calibration_loader, transform_fn) | ||
#! [dataset] | ||
|
||
#! [quantization] | ||
import torchvision | ||
from nncf.torch import disable_patching | ||
|
||
input_fp32 = torch.ones((1, 3, 224, 224)) # FP32 model input | ||
model = torchvision.models.resnet50(pretrained=True) | ||
|
||
with disable_patching(): | ||
exported_model = torch.export.export_for_training(model, args=(input_fp32,)).module() | ||
quantized_model = nncf.quantize(exported_model, calibration_dataset) | ||
#! [quantization] | ||
|
||
#! [inference] | ||
import openvino.torch | ||
|
||
input_fp32 = ... # FP32 model input | ||
|
||
# compile quantized model using torch.compile API | ||
with disable_patching(): | ||
compiled_model_int8 = torch.compile(quantized_model, backend="openvino") | ||
# OpenVINO backend compiles the model during the first call, | ||
# so the first call is expected to be slower than the following calls | ||
res = compiled_model_int8(input_fp32) | ||
|
||
# save the model | ||
exported_program = torch.export.export(quantized_model, args=(input_fp32,)) | ||
torch.export.save(exported_program, 'exported_program.pt2') | ||
#! [inference] |
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
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
21 changes: 21 additions & 0 deletions
21
src/common/transformations/include/transformations/common_optimizations/swiglu_fusion.hpp
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,21 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "openvino/pass/manager.hpp" | ||
#include "openvino/pass/matcher_pass.hpp" | ||
#include "transformations_visibility.hpp" | ||
|
||
namespace ov { | ||
namespace pass { | ||
|
||
class TRANSFORMATIONS_API SwiGLUFusion : public ov::pass::MatcherPass { | ||
public: | ||
OPENVINO_RTTI("SwiGLUFusion", "0"); | ||
SwiGLUFusion(); | ||
}; | ||
|
||
} // namespace pass | ||
} // namespace ov |
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
Oops, something went wrong.