Back out D23047144 "[2/3][lite interpreter] add metadata when saving and loading models for mobile"

Summary:
Original commit changeset: f368d00f7bae

Back out "[2/3][lite interpreter] add metadata when saving and loading models for mobile"

D23047144 (https://github.com/pytorch/pytorch/commit/e37f871e875e8b7127a0f3496c1c5e52ff8643ac)

Pull Request: https://github.com/pytorch/pytorch/pull/43516

(Note: this ignores all push blocking failures!)

Test Plan: CI

Reviewed By: xcheng16

Differential Revision: D23304639

fbshipit-source-id: 970ca3438c1858f8656cbcf831ffee2c4a551110
diff --git a/torch/csrc/jit/mobile/import.cpp b/torch/csrc/jit/mobile/import.cpp
index 65018a4..e5ff8a2 100644
--- a/torch/csrc/jit/mobile/import.cpp
+++ b/torch/csrc/jit/mobile/import.cpp
@@ -228,8 +228,6 @@
   c10::IValue readArchive(
       const std::string& archive_name,
       std::shared_ptr<mobile::CompilationUnit> mcu);
-  std::unordered_map<std::string, std::string> readMobileMetadata(
-      std::shared_ptr<mobile::CompilationUnit> mcu);
   std::shared_ptr<CompilationUnit> compilation_unit_;
   std::unordered_set<std::string> imported_libs_;
   std::unique_ptr<PyTorchStreamReader> reader_;
@@ -252,23 +250,8 @@
     debug_info_bvals = readArchive("mobile_debug", mcu).toTuple()->elements();
   }
   parseMethods(bvals, debug_info_bvals, *mcu);
-  auto meta_dict = readMobileMetadata(mcu);
-  return mobile::Module(readArchive("data", mcu).toObject(), meta_dict, mcu);
-}
 
-std::unordered_map<std::string, std::string> BytecodeDeserializer::
-    readMobileMetadata(std::shared_ptr<mobile::CompilationUnit> mcu) {
-  std::unordered_map<std::string, std::string> res;
-  if (!reader_->hasRecord("metadata.pkl")) {
-    return res;
-  }
-  auto ivalue_dict = readArchive("metadata", mcu).toGenericDict();
-  for (auto it = ivalue_dict.begin(); it != ivalue_dict.end(); ++it) {
-    auto key = it->key().toString()->string();
-    auto value = it->value().toString()->string();
-    res[key] = value;
-  }
-  return res;
+  return mobile::Module(readArchive("data", mcu).toObject(), mcu);
 }
 
 c10::IValue BytecodeDeserializer::readArchive(
diff --git a/torch/csrc/jit/mobile/module.h b/torch/csrc/jit/mobile/module.h
index ec7ef0e..f3cf448 100644
--- a/torch/csrc/jit/mobile/module.h
+++ b/torch/csrc/jit/mobile/module.h
@@ -24,15 +24,8 @@
   Module(
       c10::intrusive_ptr<c10::ivalue::Object> object,
       std::shared_ptr<CompilationUnit> cu)
-      : object_(object),
-        metadata_(std::unordered_map<std::string, std::string>()),
-        cu_(std::move(cu)) {}
-  Module(
-      c10::intrusive_ptr<c10::ivalue::Object> object,
-      std::unordered_map<std::string, std::string> metadata,
-      std::shared_ptr<CompilationUnit> cu)
-      : object_(object), metadata_(std::move(metadata)), cu_(std::move(cu)) {}
-  Module() = default;
+      : object_(object), cu_(std::move(cu)){};
+  Module() {}
   c10::IValue run_method(const std::string& method_name, Stack stack);
   c10::IValue forward(std::vector<c10::IValue> inputs) {
     return run_method("forward", std::move(inputs));
@@ -58,13 +51,9 @@
   }
   /// True if the module is in training mode.
   bool is_training() const;
-  const std::unordered_map<std::string, std::string> metadata() const {
-    return metadata_;
-  }
 
  private:
   c10::intrusive_ptr<c10::ivalue::Object> object_;
-  std::unordered_map<std::string, std::string> metadata_;
   std::shared_ptr<CompilationUnit> cu_;
 };
 } // namespace mobile
diff --git a/torch/csrc/jit/serialization/export.h b/torch/csrc/jit/serialization/export.h
index 212ed65..9a01eb7 100644
--- a/torch/csrc/jit/serialization/export.h
+++ b/torch/csrc/jit/serialization/export.h
@@ -88,13 +88,6 @@
 using ExportModuleExtraFilesHook = std::function<ExtraFilesMap(const Module&)>;
 TORCH_API void SetExportModuleExtraFilesHook(ExportModuleExtraFilesHook hook);
 
-using ExportModuleMobileInfoConverter =
-    std::function<c10::Dict<std::string, std::string>(
-        const Module&,
-        const std::unordered_map<std::string, std::string>&)>;
-TORCH_API void SetExportModuleMobileInfoConverter(
-    ExportModuleMobileInfoConverter converter);
-
 // Returns a list of names of all operators in the module and its submodules.
 TORCH_API std::vector<std::string> export_opnames(const Module& m);
 
diff --git a/torch/csrc/jit/serialization/export_module.cpp b/torch/csrc/jit/serialization/export_module.cpp
index e8aaafc..727b7ac 100644
--- a/torch/csrc/jit/serialization/export_module.cpp
+++ b/torch/csrc/jit/serialization/export_module.cpp
@@ -35,11 +35,6 @@
   return func;
 }
 
-ExportModuleMobileInfoConverter& GetMobileInfoConverter() {
-  static ExportModuleMobileInfoConverter func = nullptr;
-  return func;
-}
-
 static IValue Tup(std::vector<IValue> ivalues) {
   return c10::ivalue::Tuple::create(std::move(ivalues));
 }
@@ -247,11 +242,6 @@
   GetExtraFilesHook() = hook;
 }
 
-void SetExportModuleMobileInfoConverter(
-    ExportModuleMobileInfoConverter converter) {
-  GetMobileInfoConverter() = converter;
-}
-
 class ScriptModuleSerializer {
  public:
   explicit ScriptModuleSerializer(const std::string& filename)
@@ -279,7 +269,6 @@
     writeArchive("constants", c10::ivalue::Tuple::create(ivalue_constants));
     if (bytecode_format) {
       writeByteCode(module, save_mobile_debug_info);
-      writeMobileMetadata(module, extra_files);
     }
 
     // Acquires and sets minimum (dynamic) version
@@ -348,26 +337,6 @@
     }
   }
 
-  void writeMobileMetadata(
-      const Module& module,
-      const ExtraFilesMap& extra_files) {
-    auto hook = GetExtraFilesHook();
-    auto converter = GetMobileInfoConverter();
-    if (!converter) {
-      return;
-    }
-    ExtraFilesMap files_to_write = extra_files;
-    // merge hook files and extra files
-    if (hook) {
-      ExtraFilesMap hook_files = hook(module);
-      files_to_write.insert(hook_files.begin(), hook_files.end());
-    }
-    auto content_to_write = converter(module, files_to_write);
-    if (!content_to_write.empty()) {
-      writeArchive("metadata", content_to_write);
-    }
-  }
-
   void writeCode(const at::NamedTypePtr& root_type) {
     class_deps_.push_back(root_type);
     for (size_t i = 0; i < class_deps_.size(); ++i) {