-
Notifications
You must be signed in to change notification settings - Fork 158
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
[luci/pass] introduce quantize weight with GPTQ pass #14285
Closed
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12557d8
[luci-pass] Introduce GPTQ pass
313d3b8
[luci-pass] Add cal_offset_2d
bce1b10
Refactoring and clean-up
e0fb564
Add description, and extract variables in GPTQPass
9387b96
Add GPTQ algorithm and hessian map support for circle quantizer
3574826
Refactor GPTQPass to improve readability and maintainability
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
compiler/luci/pass/include/luci/Pass/QuantizeWeightsWithGPTQPass.h
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,82 @@ | ||||||
/* | ||||||
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
* You may obtain a copy of the License at | ||||||
* | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* | ||||||
* Unless required by applicable law or agreed to in writing, software | ||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
* See the License for the specific language governing permissions and | ||||||
* limitations under the License. | ||||||
*/ | ||||||
|
||||||
#ifndef __LUCI_QUANTIZE_WEIGHTS_WITH_GPTQ_PASS_H__ | ||||||
#define __LUCI_QUANTIZE_WEIGHTS_WITH_GPTQ_PASS_H__ | ||||||
|
||||||
#include <luci/Pass/QuantizationParameters.h> | ||||||
#include <luci/IR/CircleNode.h> | ||||||
|
||||||
#include <logo/Pass.h> | ||||||
#include <loco.h> | ||||||
|
||||||
#include <unordered_map> | ||||||
|
||||||
namespace luci | ||||||
{ | ||||||
|
||||||
using HessianMap = std::unordered_map<const luci::CircleNode *, std::vector<float>>; | ||||||
|
||||||
/** | ||||||
* @brief Pass to quantize weights | ||||||
*/ | ||||||
class QuantizeWeightsWithGPTQPass : public logo::Pass | ||||||
{ | ||||||
public: | ||||||
struct Context | ||||||
{ | ||||||
loco::DataType input_model_dtype = loco::DataType::Unknown; | ||||||
loco::DataType output_model_dtype = loco::DataType::Unknown; | ||||||
QuantizationGranularity granularity = QuantizationGranularity::ChannelWise; | ||||||
std::vector<LayerInfo> layers_info; | ||||||
}; | ||||||
|
||||||
public: | ||||||
QuantizeWeightsWithGPTQPass(std::unique_ptr<Context> &&ctx) : _ctx{std::move(ctx)} | ||||||
{ | ||||||
// DO NOTHING | ||||||
} | ||||||
|
||||||
QuantizeWeightsWithGPTQPass(std::unique_ptr<Context> &&ctx, HessianMap *hessian_map) | ||||||
: _ctx{std::move(ctx)}, _hessian_map{hessian_map} | ||||||
{ | ||||||
// DO NOTHING | ||||||
} | ||||||
|
||||||
public: | ||||||
QuantizeWeightsWithGPTQPass(loco::DataType input_model_dtype, loco::DataType output_model_dtype, | ||||||
QuantizationGranularity granularity) | ||||||
{ | ||||||
_ctx = std::make_unique<Context>(); | ||||||
{ | ||||||
_ctx->input_model_dtype = input_model_dtype; | ||||||
_ctx->output_model_dtype = output_model_dtype; | ||||||
_ctx->granularity = granularity; | ||||||
} | ||||||
} | ||||||
virtual const char *name(void) const { return "luci::QuantizeWeightsWithGPTQPass"; } | ||||||
|
||||||
public: | ||||||
bool run(loco::Graph *graph); | ||||||
|
||||||
private: | ||||||
std::unique_ptr<Context> _ctx; | ||||||
HessianMap *_hessian_map; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}; | ||||||
|
||||||
} // namespace luci | ||||||
|
||||||
#endif //__LUCI_QUANTIZE_WEIGHTS_WITH_GPTQ_PASS_H__ |
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 |
---|---|---|
|
@@ -292,6 +292,11 @@ uint32_t cal_offset(loco::TensorShape &dimension, uint32_t *indices) | |
indices[2] * dimension.dim(3).value() + indices[3]; | ||
} | ||
|
||
uint32_t cal_offset_2d(loco::TensorShape &dimension, uint32_t *indices) | ||
{ | ||
return indices[0] * dimension.dim(1).value() + indices[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know caller is calling with safe index. |
||
} | ||
|
||
// Activation (ofm) qtype is determined in different ways. | ||
// 1. Pre-defined values: Some Ops have pre-defined qparams (ex: LOGISTIC, TANH) | ||
// 2. Integer scale: Output of some Ops should be integers (ex: FLOOR, CEIL) | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this brief doesn't give any help. plz remove or give more useful description.