Skip to content

Commit 0309f6a

Browse files
jerryzh168facebook-github-bot
authored andcommitted
[quant][graphmode][fix] cloning schema in insert_observers (#40624)
Summary: Pull Request resolved: #40624 Previously we didn't clone schema, so the default schema is used, this is causing issue for some models Test Plan: Imported from OSS Differential Revision: D22259519 fbshipit-source-id: e2a393a54cb18f55da0c7152a74ddc22079ac350
1 parent 0a19534 commit 0309f6a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

torch/csrc/jit/passes/quantization/insert_observers.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,18 @@ class ModuleCloneHelper {
242242
remapTypes(graph.get(), source, target, module_qconfig_map, type_remap_fn);
243243
// remap self
244244
graph->inputs()[0]->setType(target.type());
245+
// we only support %self being Module in the arguments of function
246+
auto schema_type_remap_fn = [&](TypePtr type_ptr) {
247+
return type_remap_fn(type_ptr, module_qconfig_map.at(source._ivalue()));
248+
};
249+
auto schema =
250+
method.getSchema().cloneWithRemappedTypes(schema_type_remap_fn);
245251
const auto this_method_name =
246252
c10::QualifiedName(*target.type()->name(), method.name());
247253
auto copied = target._ivalue()->compilation_unit()->create_function(
248254
this_method_name, graph);
249255
target.type()->addMethod(copied);
250-
// we'll use default schema for cloned method
256+
copied->setSchema(std::move(schema));
251257
}
252258
};
253259

0 commit comments

Comments
 (0)