Skip to content

Commit

Permalink
Back out "Revert D40198461: [pytorch][PR] Backport currently dont wor…
Browse files Browse the repository at this point in the history
…k with some models if:" (pytorch#87124)

Summary:
reland after fixing windows build failure for OVR.

Notable change:
```
#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
```
changed to
```#if defined(FBCODE_CAFFE2) || defined(FB_XPLAT_BUILD)
```
Appearently `-DFB_XPLAT_BUILD` wasn't getting picked up in windows if using `or `to connect

Original commit changeset: 7a31fc4b455f

Original Phabricator Diff: D40198461

Test Plan: waitforsandcastle

Reviewed By: davidberard98, cccclai

Differential Revision: D40290932

Pull Request resolved: pytorch#87124
Approved by: https://github.com/gmagogsfm
  • Loading branch information
qihqi authored and pytorchmergebot committed Oct 20, 2022
1 parent f38a88c commit a42fbfa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
9 changes: 5 additions & 4 deletions buckbuild.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ def define_buck_targets(
"torch/csrc/jit/serialization/mobile_bytecode.fbs",
],
outs = {
"mobile_bytecode_generated.h": ["mobile_bytecode_generated.h"],
"mobile_bytecode_generated_fbsource.h": ["mobile_bytecode_generated.h"],
},
cmd = "$(exe {})".format(third_party("flatc")) +
" --cpp --gen-mutable --scoped-enums -o ${OUT} ${SRCS}",
Expand All @@ -1713,14 +1713,17 @@ def define_buck_targets(
name = "mobile_bytecode",
header_namespace = "",
exported_headers = {
"torch/csrc/jit/serialization/mobile_bytecode_generated.h": ":mobile_bytecode_header[mobile_bytecode_generated.h]",
"torch/csrc/jit/serialization/mobile_bytecode_generated_fbsource.h": ":mobile_bytecode_header[mobile_bytecode_generated_fbsource.h]",
},
# Avoid leaking implementation details by only exposing this header to
# the internals of the loader/serializer layer.
visibility = [
"{}:flatbuffer_loader".format(ROOT),
"{}:flatbuffer_serializer_mobile".format(ROOT),
],
exported_deps = [
third_party("flatbuffers-api"),
],
)

fb_xplat_cxx_library(
Expand All @@ -1741,7 +1744,6 @@ def define_buck_targets(
":mobile_bytecode",
":torch_mobile_module",
C10,
third_party("flatbuffers-api"),
],
exported_deps = [
":torch_mobile_train",
Expand Down Expand Up @@ -1779,7 +1781,6 @@ def define_buck_targets(
visibility = ["PUBLIC"],
deps = [
":mobile_bytecode",
third_party("flatbuffers-api"),
],
exported_deps = [
":torch_mobile_deserialize",
Expand Down
12 changes: 8 additions & 4 deletions test/cpp/jit/test_flatbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
#include <caffe2/serialize/versions.h>
#include <torch/csrc/jit/serialization/import_export_functions.h>
#include <unordered_set>

#if defined(FB_XPLAT_BUILD) || defined(FBCODE_CAFFE2)
#include <torch/csrc/jit/serialization/mobile_bytecode_generated_fbsource.h> // NOLINT
namespace flatbuffers = flatbuffers_fbsource;
#define FLATBUFFERS_MAX_ALIGNMENT FLATBUFFERS_FBSOURCE_MAX_ALIGNMENT
#else
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT
#endif
// Tests go in torch::jit
namespace torch {
namespace jit {
Expand Down Expand Up @@ -1796,13 +1804,9 @@ TEST(FlatbufferUpgraderTest, DivScalarInplaceIntV2) {

} // namespace jit
} // namespace torch
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h>
namespace torch {
namespace jit {

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
namespace flatbuffers = flatbuffers_fbsource;
#endif
/**
* An Allocator that can only deallocate (using delete []), counting
* the number of times that it has been asked to deallocate.
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/mobile/compatibility/backport_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <torch/csrc/jit/mobile/import.h>
#include <torch/csrc/jit/mobile/module.h>
#include <torch/csrc/jit/serialization/export.h>
#include <torch/csrc/jit/serialization/flatbuffer_serializer_jit.h>
#include <torch/csrc/jit/serialization/import.h>
#include <torch/csrc/jit/serialization/pickler.h>
#include <cstddef>
Expand Down Expand Up @@ -503,6 +504,7 @@ std::stringstream backport_v7_to_v6(std::stringstream& input_model_stream) {

std::stringstream backport_v9_to_v8(std::stringstream& input_model_stream) {
ExtraFilesMap extra_files;
register_flatbuffer_all();
Module torch_script =
torch::jit::load(input_model_stream, c10::nullopt, extra_files);
std::stringstream intermediate_model_stream;
Expand Down
6 changes: 4 additions & 2 deletions torch/csrc/jit/mobile/flatbuffer_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <torch/csrc/jit/serialization/export_bytecode.h>
#include <torch/csrc/jit/serialization/import_export_constants.h>
#include <torch/csrc/jit/serialization/import_read.h>
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h>
#include <torch/custom_class.h>

#ifndef DISABLE_UPGRADER
Expand All @@ -50,9 +49,12 @@
#include <cstdlib>
#endif

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
#if defined(FB_XPLAT_BUILD) || defined(FBCODE_CAFFE2)
#include <torch/csrc/jit/serialization/mobile_bytecode_generated_fbsource.h> // NOLINT
namespace flatbuffers = flatbuffers_fbsource;
#define FLATBUFFERS_MAX_ALIGNMENT FLATBUFFERS_FBSOURCE_MAX_ALIGNMENT
#else
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT
#endif

namespace torch {
Expand Down
6 changes: 4 additions & 2 deletions torch/csrc/jit/serialization/flatbuffer_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#include <torch/csrc/jit/mobile/train/export_data.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/runtime/instruction.h>
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT

#if defined(FBCODE_CAFFE2) or defined(FB_XPLAT_BUILD)
#if defined(FB_XPLAT_BUILD) || defined(FBCODE_CAFFE2)
#include <torch/csrc/jit/serialization/mobile_bytecode_generated_fbsource.h> // NOLINT
namespace flatbuffers = flatbuffers_fbsource;
#define FLATBUFFERS_MAX_ALIGNMENT FLATBUFFERS_FBSOURCE_MAX_ALIGNMENT
#else
#include <torch/csrc/jit/serialization/mobile_bytecode_generated.h> // NOLINT
#endif

namespace torch {
Expand Down

0 comments on commit a42fbfa

Please sign in to comment.