Skip to content

Commit a682ff7

Browse files
dreissfacebook-github-bot
authored andcommitted
Add kMaxSupportedBytecodeVersion for Lite Interpreter (pytorch#59472)
Summary: Pull Request resolved: pytorch#59472 Previously, the lite interpreter would refuse to load any model with a version greater than kProducedBytecodeVersion. Now, we're able to independently advance the loading and saving code, so we can roll out changes without breaking forward compatibility. Test Plan: CI. Loaded a bytecode v5 model even with setting kProducedBytecodeVersion to v4. Reviewed By: raziel Differential Revision: D28904350 fbshipit-source-id: 598c22f0adf47d4ed3e976bcbebdf3959dacb1df
1 parent d125694 commit a682ff7

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

caffe2/serialize/versions.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ constexpr uint64_t kProducedBytecodeVersion = 0x5L;
7676
static_assert(kProducedBytecodeVersion >= kProducedFileFormatVersion,
7777
"kProducedBytecodeVersion must be higher or equal to kProducedFileFormatVersion.");
7878

79-
// Introduce kMinSupportedBytecodeVersion for limited backward compatibility
80-
// support of bytecode. If
81-
// kMinSupportedBytecodeVersion <= model_version <= kProducedBytecodeVersion (in loader),
79+
// Introduce kMinSupportedBytecodeVersion and kMaxSupportedBytecodeVersion
80+
// for limited backward/forward compatibility support of bytecode. If
81+
// kMinSupportedBytecodeVersion <= model_version <= kMaxSupportedBytecodeVersion (in loader),
8282
// we should support this model_version. For example, we provide a wrapper to
8383
// handle an updated operator.
8484
constexpr uint64_t kMinSupportedBytecodeVersion = 0x3L;
85+
constexpr uint64_t kMaxSupportedBytecodeVersion = 0x5L;
86+
8587
} // namespace serialize
8688
} // namespace caffe2

test/cpp/jit/test_lite_interpreter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ TEST(LiteInterpreterTest, TwoSubmodulesModuleInfo) {
610610
TEST(LiteInterpreterTest, GetRuntimeByteCodeVersion) {
611611
auto runtime_bytecode_version = _get_runtime_bytecode_version();
612612
AT_ASSERT(
613-
runtime_bytecode_version == caffe2::serialize::kProducedBytecodeVersion);
613+
runtime_bytecode_version ==
614+
caffe2::serialize::kMaxSupportedBytecodeVersion);
614615
}
615616

616617
TEST(LiteInterpreterTest, GetByteCodeVersion) {

torch/csrc/jit/mobile/import.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ void BytecodeDeserializer::parseMethods(
310310
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
311311
caffe2::serialize::kMinSupportedBytecodeVersion <= model_version &&
312312
// NOLINTNEXTLINE(clang-diagnostic-sign-compare)
313-
model_version <= caffe2::serialize::kProducedBytecodeVersion,
313+
model_version <= caffe2::serialize::kMaxSupportedBytecodeVersion,
314314
"Lite Interpreter verson number does not match. ",
315315
"The model version must be between ",
316316
caffe2::serialize::kMinSupportedBytecodeVersion,
317317
" and ",
318-
caffe2::serialize::kProducedBytecodeVersion,
318+
caffe2::serialize::kMaxSupportedBytecodeVersion,
319319
"But the model version is ",
320320
model_version);
321321

torch/csrc/jit/mobile/runtime_compatibility.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace torch {
77
namespace jit {
88

99
uint64_t _get_runtime_bytecode_version() {
10-
return caffe2::serialize::kProducedBytecodeVersion;
10+
return caffe2::serialize::kMaxSupportedBytecodeVersion;
1111
}
1212

1313
/*

0 commit comments

Comments
 (0)