-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relay] Prepare for new plan_devices.cc (part II) #9130
Conversation
These changes came from changing apache#9038 to use tvm.parser.fromtext instead of manual AST construction. - Demote FunctionOnDeviceAttrs to just a pair of DictAttrs entries so that the parser will understand them on Function definitions. - Connect some special operators to their attributes so parsing understands them at call sites. - Don't silently ignore attributes during parsing. - Implement OptFunctionOnDevice so won't add device annotations for kUnknownDeviceType. - Allow the parser to be given an initial metadata map to support examples which need constants. - More DLOG -> VLOG conversions to reduce debug clutter.
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.
Overall looks straight forward, just missing a test case and minor tweaking but otherwise seems non-controversial 😸
def parse(source, source_name="from_string"): | ||
return _ffi_api.ParseModule(source_name, source) | ||
def parse(source, source_name="from_string", init_module=None, init_meta_table=None): | ||
if init_meta_table is None: |
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 can be defaulted in the arguments.
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.
Done. (I had the obvious default but clion was warning about mutable defaults and suggest this instead.)
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.
Oh, the linter complains about it too "Dangerous default value {} as argument" - I'll go back to the silly form.
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.
You can't default Python arguments to anything but atomic values. If you use an object or other aggregate data structure the default will be allocated a single time, and only a single time. If you happen to mutate it you will observe the entire history of mutations across all invocations of the function inside the process.
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.
Ah, thanks! Not so silly a rule after all.
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.
I'd suggest the language behaviour is the silly part? 👍
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.
I'd suggest the language behaviour is the silly part? 👍
Yeah its not a good design, but alas you gotta love the Python you are with 😆 it has burned many people many times, super sharp edge.
@@ -92,6 +91,7 @@ RELAY_REGISTER_OP("on_device") | |||
.add_argument("data", "Tensor", "The input data.") | |||
.set_support_level(10) | |||
.add_type_rel("Identity", IdentityRel) | |||
.set_attrs_type_key("relay.attrs.OnDeviceAttrs") |
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.
Is this still required now you've split the attributes?
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.
Yes, this is for the "on_device" operator which still uses OnDeviceAttrs on every CallNode. The split only applies to Function DictAttrs attrs which apply on definitions.
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.
Ahhh, how very exciting 👍
for (const auto& pair : init_meta_table) { | ||
Array<ObjectRef> items; | ||
if (meta_data_table.count(pair.first)) { | ||
items = meta_data_table[pair.first]; | ||
} | ||
for (const auto& obj : pair.second) { | ||
items.push_back(obj); | ||
} | ||
meta_data_table.Set(pair.first, items); | ||
} |
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.
I can't see any test cases for this logic, is it possible for you to add one so I can see it in action? 😸
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.
Good call - done.
* See also OnDeviceAttrs in include/tvm/relay/attrs/annotation.h for the companion "on_device" | ||
* call attributes. | ||
*/ | ||
struct FunctionOnDeviceAttrs : public tvm::AttrsNode<FunctionOnDeviceAttrs> { |
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.
It's a shame about this, this increases my nervousness around apache/tvm-rfcs#29 having issues as well 😿
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.
On principle it would be nice if IRModule can be round tripped via the text form (both starting from text and starting from IRModule), so we'll need to push the attrs field addition into the parser/pretty printer. Ideally that would just be a matter of calling ParseAttrs as we already do for function calls, but yeah there's no support for anything other than primitive literals in that.
I'll admit that pushes me more towards introducing a CompilerConfig class to collect targets etc and passing it explicitly rather than embedding it in the IRModule. Maybe take that back to #29?
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.
Mhm, not a discussion for here, and I'm fairly sure we can adopt it later if necessary - even if it's not carved into the stone tablet of the RFC.
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.
I already reviewed in the other PR.
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.
LGTM! 👍
* main: Fix flaky NMS test by making sure scores are unique (apache#9140) [Relay] Merge analysis/context_analysis.cc and transforms/device_annotation.cc (apache#9038) [LLVM] Make changes needed for opaque pointers (apache#9138) Arm(R) Ethos(TM)-U NPU codegen integration (apache#8849) [CI] Split Integration tests out of first phase of pipeline (apache#9128) [Meta Schedule][M3b] Runner (apache#9111) Fix Google Mock differences between Ubuntu 18.04 and 16.04 (apache#9141) [TIR] add loop partition hint pragma (apache#9121) fix things (apache#9146) [Meta Schedule][M3a] SearchStrategy (apache#9132) [Frontend][PyTorch] support for quantized conv_transpose2d op (apache#9133) [UnitTest] Parametrized test_conv2d_int8_intrinsics (apache#9143) [OpenCL] Remove redundant visit statement in CodeGen. (apache#9144) [BYOC] support arbitrary input dims for add/mul/relu of dnnl c_src codegen (apache#9127) [Relay][ConvertLayout] Support for qnn.conv2d_transpose (apache#9139) add nn.global_avgpool to fq2i (apache#9137) [UnitTests] Enable minimum testing on Vulkan target in CI (apache#9093) [Torch] Support returning quantized weights and bias for BYOC use cases (apache#9135) [Relay] Prepare for new plan_devices.cc (part II) (apache#9130) [microTVM][Zephyr] Add MIMXRT1050 board support (apache#9068)
* Prepare for new plan_devices.cc (part II) These changes came from changing apache#9038 to use tvm.parser.fromtext instead of manual AST construction. - Demote FunctionOnDeviceAttrs to just a pair of DictAttrs entries so that the parser will understand them on Function definitions. - Connect some special operators to their attributes so parsing understands them at call sites. - Don't silently ignore attributes during parsing. - Implement OptFunctionOnDevice so won't add device annotations for kUnknownDeviceType. - Allow the parser to be given an initial metadata map to support examples which need constants. - More DLOG -> VLOG conversions to reduce debug clutter. * [checkpoint] Keep existing ParseModule ffi to simplify rust bindings * [checkpoint] Address Christopher's comments. * [checkpoint] Andrew's comments from apache#9038 * [checkpoint] Jared's comments from apache#9038 * [checkpoint] Woops, forgot rename.
* Prepare for new plan_devices.cc (part II) These changes came from changing apache#9038 to use tvm.parser.fromtext instead of manual AST construction. - Demote FunctionOnDeviceAttrs to just a pair of DictAttrs entries so that the parser will understand them on Function definitions. - Connect some special operators to their attributes so parsing understands them at call sites. - Don't silently ignore attributes during parsing. - Implement OptFunctionOnDevice so won't add device annotations for kUnknownDeviceType. - Allow the parser to be given an initial metadata map to support examples which need constants. - More DLOG -> VLOG conversions to reduce debug clutter. * [checkpoint] Keep existing ParseModule ffi to simplify rust bindings * [checkpoint] Address Christopher's comments. * [checkpoint] Andrew's comments from apache#9038 * [checkpoint] Jared's comments from apache#9038 * [checkpoint] Woops, forgot rename.
These changes came from changing #9038 to use
tvm.parser.fromtext instead of manual AST construction.
that the parser will understand them on Function definitions.
at call sites.
need constants.