Skip to content

Commit

Permalink
[Unity][MSC][M2.4] Add quantizer for quantize model (#16228)
Browse files Browse the repository at this point in the history
* add quantizer

* add quantizer test
  • Loading branch information
Archermmt authored Dec 15, 2023
1 parent a2e19d2 commit 8edfee8
Show file tree
Hide file tree
Showing 26 changed files with 2,344 additions and 4 deletions.
8 changes: 8 additions & 0 deletions python/tvm/contrib/msc/core/runtime/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,14 @@ def apply_tool(self, tool_type: str, data_loader: Any = None) -> str:
self.run(inputs, ret_type="native")
break
plan = pruner.finalize()
elif tool_type == ToolType.QUANTIZER:
quantizer = self.get_tool(ToolType.QUANTIZER)
while not quantizer.calibrated:
assert data_loader, "data_loader should be given to plan prune"
for inputs in data_loader():
self.run(inputs, ret_type="native")
quantizer.calibrate()
plan = quantizer.finalize()
else:
plan = self.get_tool(tool_type).finalize()
assert plan, "Failed to create plan for {}".format(tool_type)
Expand Down
1 change: 1 addition & 0 deletions python/tvm/contrib/msc/core/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
from .tool import *
from .execute import *
from .prune import *
from .quantize import *
from .track import *
20 changes: 20 additions & 0 deletions python/tvm/contrib/msc/core/tools/quantize/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
"""tvm.contrib.msc.core.tools.quantize"""

from .quantizer import *
from .method import *
Loading

0 comments on commit 8edfee8

Please sign in to comment.