mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
[JIT] Print out interface mismatch for prim::ModuleDictIndex (#47300)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/47300 **Summary** This commit augments the module interface subtyping check that is done before the emission of the `prim::ModuleDictIndex` operator so that the error message that is printed if the subtyping check fails provides more information on which methods do not match. **Test Plan** Existing unit tests for `prim::ModuleDictIndex`. Compilation of `ModWithWrongAnnotation` now produces this error: ``` Attribute module is not of annotated type __torch__.jit.test_module_containers.ModuleInterface: Method on class '__torch__.jit.test_module_containers.DoesNotImplementInterface' (1) is not compatible with interface '__torch__.jit.test_module_containers.ModuleInterface' (2) (1) forward(__torch__.jit.test_module_containers.DoesNotImplementInterface self, Tensor inp) -> ((Tensor, Tensor)) (2) forward(InterfaceType<ModuleInterface> self, Any inp) -> (Any) : ``` Test Plan: Imported from OSS Reviewed By: navahgar Differential Revision: D24709538 Pulled By: SplitInfinity fbshipit-source-id: 6b6cb75e4b2b12b08576a5530b4b90cbcad9b6e5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
14194e4f23
commit
dc0d68a1ee
@ -260,11 +260,13 @@ SugaredValuePtr ModuleValue::getitem(
|
||||
for (size_t i = 0; i < self_type->numAttributes(); ++i) {
|
||||
const auto& attr_type = self_type->getAttribute(i);
|
||||
if (attr_type->is_module()) {
|
||||
if (!attr_type->isSubtypeOf(type_hint)) {
|
||||
std::stringstream ss;
|
||||
if (!attr_type->isSubtypeOfExt(type_hint, &ss)) {
|
||||
auto loc = self_->node()->sourceRange();
|
||||
throw ErrorReport(loc)
|
||||
<< "Attribute " << self_type->getAttributeName(i)
|
||||
<< " is not of annotated type " << type_hint->annotation_str();
|
||||
<< " is not of annotated type " << type_hint->annotation_str()
|
||||
<< ": " << ss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user