samskalicky commented on a change in pull request #17530: Add deferred compute
support
URL: https://github.com/apache/incubator-mxnet/pull/17530#discussion_r379848171
##########
File path: src/imperative/imperative.cc
##########
@@ -273,8 +288,126 @@ void Imperative::RecordOp(
info.outputs.back().dtype_ = outputs[i]->dtype();
info.outputs.back().storage_type_ = outputs[i]->storage_type();
}
- outputs[i]->entry_ = nnvm::NodeEntry{node, i, 0};
+ outputs[i]->autograd_entry_ = nnvm::NodeEntry{node, i, 0};
+ }
+}
+
+void Imperative::RecordDeferredCompute(nnvm::NodeAttrs &&attrs,
+ const std::vector<NDArray *> &inputs,
+ const std::vector<NDArray *> &outputs) {
+ CHECK(!is_recording())
+ << "Autograd recording is not supported during deferred compute mode.";
+
+ for (const NDArray *output : outputs) {
+ CHECK(DCInfo::IsNone(*output))
+ << "Inplace operations (+=, -=, x[:]=, etc) are not supported when "
+ << "recording in deferred compute mode.";
+ // However, an inplace operation on a non-deferred compute array inside
+ // deferred compute scope will work. For example:
+ // a = mx.nd.arange(10)
+ // with dc.context():
+ // a[:5] = 0
+ }
+ DispatchMode dispatch_mode = DispatchMode::kUndefined;
+ Context default_ctx = Context::CPU();
+ Context ctx = imperative::GetContext(attrs, inputs, outputs, default_ctx);
Review comment:
nit: do we need to declare default_ctx rather than just pass
`Context::CPU()` into the `GetContext` function?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services