Skip to content

Commit

Permalink
[Pytorch Edge] Minor improve documentation in test_backend_with_compiler
Browse files Browse the repository at this point in the history
Summary:
Went through all these files and the design doc to understand the to_backend api. Figured I could add some comments to these files to make the apis a little clearer for those that come after.

(Note: this ignores all push blocking failures!)

Test Plan: na

Reviewed By: raziel, larryliu0820

Differential Revision: D34221989

fbshipit-source-id: 699fcbd8714bfb6b58c6c0bf0e5fbc019d2ef6f8
(cherry picked from commit 0b3f5d73e8de216b4402aed2f2b80be8781f145b)
  • Loading branch information
JacobSzwejbka authored and cyyever committed Feb 17, 2022
1 parent fc0e67a commit 20f8cdf
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/cpp/jit/test_backend_compiler_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ class BackendWithCompiler : public PyTorchBackendInterface {
return true;
}

// Since the actual compilation is done AOT,
// Since the actual compilation is done AOT for this backend, compile just
// forwards everything along. In a non toy setup this could grab information
// from that runtime that might be relevant to execute, such as build flags
// the resolution of the devices camera, or basically any runtime specific
// information that wouldnt be available server side where preprocess is
// called.
c10::impl::GenericDict compile(
c10::IValue processed,
c10::impl::GenericDict method_compile_spec) override {
Expand All @@ -86,8 +91,14 @@ class BackendWithCompiler : public PyTorchBackendInterface {
return c10::impl::toGenericDict(handles);
}

// Function that actually executes the model in the backend. Here there is
// nothing to dispatch to, so the backend is implemented locally within
// execute and it only supports add, subtract, and constant. In a non toy
// backend you can imagine how this function could be used to actually
// dispatch the inputs to the relevant backend/device.
c10::impl::GenericList execute(
c10::IValue handle,
c10::IValue
handle, // example: [('prim::Constant#1', 14), ('aten::add', 15)]
c10::impl::GenericList inputs) override {
TORCH_INTERNAL_ASSERT(inputs.size() == 2);
c10::IValue val0 = inputs[0];
Expand All @@ -107,6 +118,7 @@ class BackendWithCompiler : public PyTorchBackendInterface {
auto start_time_us = torch::profiler::impl::getTime() / 1000;
try {
if (instruction.rfind("prim::Constant", 0) == 0) {
// 15 is the length of 'prim::Constant#' the constant val comes after
TORCH_CHECK(
instruction.size() > 15,
"Constant value is expected in ",
Expand Down

0 comments on commit 20f8cdf

Please sign in to comment.