Skip to content
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

[MSC][M5.3] Support torch.dynamo for dynamic models #16772

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions gallery/how_to/work_with_msc/using_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@
parser.add_argument("--test_iter", type=int, default=100, help="The iter for test")
parser.add_argument("--calibrate_iter", type=int, default=100, help="The iter for calibration")
parser.add_argument("--train_batch", type=int, default=32, help="The batch size for train")
parser.add_argument("--train_iter", type=int, default=200, help="The iter for train")
parser.add_argument("--train_epoch", type=int, default=100, help="The epoch for train")
parser.add_argument("--train_iter", type=int, default=100, help="The iter for train")
parser.add_argument("--train_epoch", type=int, default=5, help="The epoch for train")
parser.add_argument(
"--verbose", type=str, default="info", help="The verbose level, info|debug:1,2,3|critical"
)
parser.add_argument("--dynamic", action="store_true", help="Whether to use dynamic wrapper")
args = parser.parse_args()


Expand All @@ -88,8 +89,8 @@ def get_config(calib_loader, train_loader):
compile_type=args.compile_type,
dataset=dataset,
tools=tools,
skip_config={"all": "check"},
verbose=args.verbose,
dynamic=args.dynamic,
)


Expand All @@ -100,13 +101,13 @@ def _get_calib_datas():
for i, (inputs, _) in enumerate(testloader, 0):
if i >= args.calibrate_iter > 0:
break
yield {"input": inputs}
yield inputs if args.dynamic else {"input": inputs}

def _get_train_datas():
for i, (inputs, _) in enumerate(trainloader, 0):
if i >= args.train_iter > 0:
break
yield {"input": inputs}
yield inputs if args.dynamic else {"input": inputs}

model = resnet50(pretrained=args.checkpoint)
if torch.cuda.is_available():
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/contrib/msc/core/gym/environment/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _get_loss(golden, result):
outputs = runner.run(inputs)
baseline = loader[idx]
for name, data in outputs.items():
loss += _get_loss(baseline[name], data)
loss += _get_loss(baseline[name], msc_utils.cast_array(data))
return {"loss": loss / len(loader)}

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _summary(self, actions: List[dict], rewards: List[dict]) -> Union[dict, str]
continue
info.update(strategys[name].get_executor(msc_utils.MSCStage.QUANTIZE).config)
summary_file = msc_utils.get_cache_dir().relpath("gym_summary.json")
return msc_utils.dump_dict(plan, summary_file)
return msc_utils.save_dict(plan, summary_file)

@classmethod
def role_type(cls):
Expand Down
1 change: 1 addition & 0 deletions python/tvm/contrib/msc/core/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
"""tvm.contrib.msc.core.runtime"""

from .runner import *
from .jit import *
Loading
Loading