From 361b295d92824ba8349d73564bad190803d22955 Mon Sep 17 00:00:00 2001 From: zhenyan-zhang-meta Date: Tue, 29 Apr 2025 22:43:51 -0700 Subject: [PATCH 1/3] [ExecuTorch] Separate `extension.Module` Namespaces from Aten and non-Aten Separate `extension.Module` Namespaces to be `executorch::extension::module` and `executorch::extension::module_aten`, otherwise in the future there will be issues like P1799454769. It's similar to what we already did for bundled_program in https://github.com/pytorch/executorch/pull/10307 Differential Revision: [D73903870](https://our.internmc.facebook.com/intern/diff/D73903870/) [ghstack-poisoned] --- docs/source/extension-module.md | 2 ++ docs/source/extension-tensor.md | 2 ++ docs/source/getting-started.md | 1 + docs/source/llm/getting-started.md | 2 +- docs/source/using-executorch-cpp.md | 1 + examples/llm_manual/main.cpp | 2 +- examples/models/llama/runner/runner.cpp | 2 +- examples/models/llama/runner/runner.h | 2 +- .../llava/runner/llava_image_prefiller.h | 3 ++- .../llava/runner/llava_text_decoder_runner.h | 3 ++- examples/models/phi-3-mini/runner.cpp | 2 +- examples/models/phi-3-mini/runner.h | 2 +- .../oss_scripts/llama/runner/io_manager.cpp | 2 +- .../oss_scripts/llama/runner/io_manager.h | 16 +++++++++++----- .../oss_scripts/llama/runner/runner.cpp | 2 +- .../oss_scripts/llama/runner/runner.h | 4 +++- .../qaihub_scripts/llama/runner/io_memory.cpp | 2 +- .../qaihub_scripts/llama/runner/io_memory.h | 16 ++++++++++++---- .../qaihub_scripts/llama/runner/runner.cpp | 2 +- .../qaihub_scripts/llama/runner/runner.h | 4 +++- .../stable_diffusion/runner/runner.cpp | 2 +- .../stable_diffusion/runner/runner.h | 4 +++- extension/android/jni/jni_layer.cpp | 1 + .../ExecuTorch/Exported/ExecuTorchModule.mm | 1 + extension/llm/runner/image_prefiller.h | 5 ++++- extension/llm/runner/multimodal_runner.h | 2 ++ extension/llm/runner/text_decoder_runner.h | 2 ++ extension/module/module.cpp | 2 ++ extension/module/module.h | 10 +++++++++- extension/module/test/module_test.cpp | 1 + extension/training/module/training_module.cpp | 19 ++++++++++++------- extension/training/module/training_module.h | 4 ++-- 32 files changed, 89 insertions(+), 36 deletions(-) diff --git a/docs/source/extension-module.md b/docs/source/extension-module.md index 835c5c12e27..d5bcddf9a65 100644 --- a/docs/source/extension-module.md +++ b/docs/source/extension-module.md @@ -13,6 +13,7 @@ Let's see how we can run the `SimpleConv` model generated from the [Exporting to #include using namespace ::executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Create a Module. Module module("/path/to/model.pte"); @@ -221,6 +222,7 @@ Use [ExecuTorch Dump](etdump.md) to trace model execution. Create an `ETDumpGen` #include using namespace ::executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; Module module("/path/to/model.pte", Module::LoadMode::MmapUseMlock, std::make_unique()); diff --git a/docs/source/extension-tensor.md b/docs/source/extension-tensor.md index 910c06053ed..fdfc72a2227 100644 --- a/docs/source/extension-tensor.md +++ b/docs/source/extension-tensor.md @@ -11,6 +11,7 @@ Imagine you’re working with a [`Module`](extension-module.md) interface, and y using namespace executorch::aten; using namespace executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; SizesType sizes[] = {2, 3}; DimOrderType dim_order[] = {0, 1}; @@ -42,6 +43,7 @@ Here’s how you can use it: #include using namespace executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; auto tensor = make_tensor_ptr( {2, 3}, // sizes diff --git a/docs/source/getting-started.md b/docs/source/getting-started.md index b7a97190b49..a2c64d07663 100644 --- a/docs/source/getting-started.md +++ b/docs/source/getting-started.md @@ -194,6 +194,7 @@ Loading and running a model using the high-level API can be done as follows: #include using namespace ::executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Load the model. Module module("/path/to/model.pte"); diff --git a/docs/source/llm/getting-started.md b/docs/source/llm/getting-started.md index 152162841e4..522529a1eac 100644 --- a/docs/source/llm/getting-started.md +++ b/docs/source/llm/getting-started.md @@ -209,7 +209,7 @@ Create a file called main.cpp with the following contents: using executorch::aten::ScalarType; using executorch::aten::Tensor; using executorch::extension::from_blob; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::runtime::EValue; using executorch::runtime::Result; ``` diff --git a/docs/source/using-executorch-cpp.md b/docs/source/using-executorch-cpp.md index d64dad97da9..46c0c15c39b 100644 --- a/docs/source/using-executorch-cpp.md +++ b/docs/source/using-executorch-cpp.md @@ -13,6 +13,7 @@ In addition the Module class, the tensor extension provides an encapsulated inte #include using namespace ::executorch::extension; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Load the model. Module module("/path/to/model.pte"); diff --git a/examples/llm_manual/main.cpp b/examples/llm_manual/main.cpp index 76492513f91..a1ae207db96 100644 --- a/examples/llm_manual/main.cpp +++ b/examples/llm_manual/main.cpp @@ -20,7 +20,7 @@ using executorch::aten::ScalarType; using executorch::aten::Tensor; using executorch::extension::from_blob; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::runtime::EValue; using executorch::runtime::Result; diff --git a/examples/models/llama/runner/runner.cpp b/examples/models/llama/runner/runner.cpp index 186c2013616..c6df62658fd 100644 --- a/examples/models/llama/runner/runner.cpp +++ b/examples/models/llama/runner/runner.cpp @@ -21,7 +21,7 @@ namespace example { -using ::executorch::extension::Module; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; using ::executorch::runtime::Error; using ::executorch::runtime::Result; diff --git a/examples/models/llama/runner/runner.h b/examples/models/llama/runner/runner.h index 97ffe4b98b7..9cc9deaf586 100644 --- a/examples/models/llama/runner/runner.h +++ b/examples/models/llama/runner/runner.h @@ -60,7 +60,7 @@ class ET_EXPERIMENTAL Runner : public executorch::extension::llm::IRunner { bool shouldStop_{false}; // model - std::unique_ptr<::executorch::extension::Module> module_; + std::unique_ptr<::executorch::extension::ET_MODULE_NAMESPACE::Module> module_; std::string tokenizer_path_; std::unique_ptr<::tokenizers::Tokenizer> tokenizer_; std::unordered_map metadata_; diff --git a/examples/models/llava/runner/llava_image_prefiller.h b/examples/models/llava/runner/llava_image_prefiller.h index 762a28d0d07..aa377d1528d 100644 --- a/examples/models/llava/runner/llava_image_prefiller.h +++ b/examples/models/llava/runner/llava_image_prefiller.h @@ -18,7 +18,8 @@ namespace example { class ET_EXPERIMENTAL LlavaImagePrefiller : public ::executorch::extension::llm::ImagePrefiller { public: - explicit LlavaImagePrefiller(::executorch::extension::Module* module) + explicit LlavaImagePrefiller( + ::executorch::extension::ET_MODULE_NAMESPACE::Module* module) : ImagePrefiller(module){}; /** * Prefill an LLM Module with the given image input. diff --git a/examples/models/llava/runner/llava_text_decoder_runner.h b/examples/models/llava/runner/llava_text_decoder_runner.h index 3de418b57ea..cbec7dd927d 100644 --- a/examples/models/llava/runner/llava_text_decoder_runner.h +++ b/examples/models/llava/runner/llava_text_decoder_runner.h @@ -17,7 +17,8 @@ namespace example { class ET_EXPERIMENTAL LlavaTextDecoderRunner : public executorch::extension::llm::TextDecoderRunner { public: - explicit LlavaTextDecoderRunner(executorch::extension::Module* module) + explicit LlavaTextDecoderRunner( + executorch::extension::ET_MODULE_NAMESPACE::Module* module) : TextDecoderRunner(module, true) {} inline executorch::runtime::Result step( diff --git a/examples/models/phi-3-mini/runner.cpp b/examples/models/phi-3-mini/runner.cpp index 15f76e9522c..8b5457c62ec 100644 --- a/examples/models/phi-3-mini/runner.cpp +++ b/examples/models/phi-3-mini/runner.cpp @@ -16,7 +16,7 @@ #include using executorch::aten::ScalarType; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::extension::llm::Sampler; using executorch::runtime::Error; using tokenizers::Llama2cTokenizer; diff --git a/examples/models/phi-3-mini/runner.h b/examples/models/phi-3-mini/runner.h index 2f0042a57ea..fcb6cd71efa 100644 --- a/examples/models/phi-3-mini/runner.h +++ b/examples/models/phi-3-mini/runner.h @@ -42,7 +42,7 @@ class Runner { uint64_t prefill(std::vector& tokens); uint64_t run_model_step(uint64_t token); - std::unique_ptr module_; + std::unique_ptr module_; std::unique_ptr tokenizer_; std::unique_ptr sampler_; }; diff --git a/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp b/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp index c2bf7b04fbb..8bdcc462923 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp +++ b/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp @@ -12,7 +12,7 @@ using executorch::aten::Tensor; using executorch::aten::TensorImpl; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::runtime::Error; using executorch::runtime::MemoryAllocator; using executorch::runtime::MethodMeta; diff --git a/examples/qualcomm/oss_scripts/llama/runner/io_manager.h b/examples/qualcomm/oss_scripts/llama/runner/io_manager.h index 0f10eef8ddc..5a305fa7406 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/io_manager.h +++ b/examples/qualcomm/oss_scripts/llama/runner/io_manager.h @@ -20,6 +20,8 @@ #include #include +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; + namespace example { enum EvalMode { @@ -29,8 +31,8 @@ enum EvalMode { }; class IoMgrBase { public: - IoMgrBase( - std::vector>& modules); + IoMgrBase(std::vector>& modules); virtual ~IoMgrBase(); virtual void init_io() = 0; virtual void reset_io( @@ -81,13 +83,16 @@ class IoMgrBase { std::string, std::vector>> output_tensors_; - std::vector> modules_; + std::vector< + std::shared_ptr> + modules_; }; class ShiftPointerIoMgr : public IoMgrBase { public: ShiftPointerIoMgr( - std::vector>& modules, + std::vector>& modules, int32_t context_len, int32_t prefill_ar_len, int32_t prefill_cache_len, @@ -199,7 +204,8 @@ class ShiftPointerIoMgr : public IoMgrBase { class SmartMaskIoMgr : public IoMgrBase { public: SmartMaskIoMgr( - std::vector>& modules, + std::vector>& modules, int32_t context_len, int32_t prefill_ar_len, int32_t prefill_cache_len, diff --git a/examples/qualcomm/oss_scripts/llama/runner/runner.cpp b/examples/qualcomm/oss_scripts/llama/runner/runner.cpp index dafc911a172..7e7c48a517e 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/runner.cpp +++ b/examples/qualcomm/oss_scripts/llama/runner/runner.cpp @@ -23,7 +23,7 @@ #include using executorch::aten::Tensor; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::extension::llm::Sampler; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; diff --git a/examples/qualcomm/oss_scripts/llama/runner/runner.h b/examples/qualcomm/oss_scripts/llama/runner/runner.h index e693bcd7077..93c3440a503 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/runner.h +++ b/examples/qualcomm/oss_scripts/llama/runner/runner.h @@ -101,7 +101,9 @@ class Runner { std::unordered_set eos_id_; const int32_t n_bos_; const int32_t n_eos_; - std::vector> modules_; + std::vector< + std::shared_ptr> + modules_; std::string tokenizer_path_; std::string performance_output_path_; float logits_scale_; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp index 9ee7551650a..8a5ddcd7ded 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp +++ b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp @@ -14,7 +14,7 @@ using executorch::aten::Tensor; using executorch::aten::TensorImpl; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::runtime::Error; using executorch::runtime::MethodMeta; using executorch::runtime::Result; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h index 445be2ed21a..012f40404b4 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h +++ b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h @@ -32,7 +32,9 @@ class Memory { public: Memory( const std::vector& pos_embs_path, - std::vector>& modules); + std::vector< + std::shared_ptr>& + modules); virtual ~Memory(); virtual void prepare_io( const std::vector< @@ -51,7 +53,9 @@ class Memory { std::vector> input_tensors_; std::vector> output_tensors_; std::vector pos_embs_path_; - std::vector> modules_; + std::vector< + std::shared_ptr> + modules_; std::vector method_names_; }; @@ -59,7 +63,9 @@ class BertMemory : public Memory { public: BertMemory( const std::vector& pos_embs_path, - std::vector>& modules, + std::vector< + std::shared_ptr>& + modules, std::vector shard_layers); void prepare_io(const std::vector>& methods_meta) override; @@ -121,7 +127,9 @@ class KVCachedMemory : public Memory { public: KVCachedMemory( const std::vector& pos_embs_path, - std::vector>& modules, + std::vector< + std::shared_ptr>& + modules, std::vector shard_layers); void prepare_io(const std::vector>& methods_meta) override; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp b/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp index 06ea324ef6f..cb98fcf04f3 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp +++ b/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp @@ -30,7 +30,7 @@ #endif using executorch::aten::Tensor; -using executorch::extension::Module; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::extension::llm::Sampler; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/runner.h b/examples/qualcomm/qaihub_scripts/llama/runner/runner.h index 9672d6a3586..effd2ca8c50 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/runner.h +++ b/examples/qualcomm/qaihub_scripts/llama/runner/runner.h @@ -97,7 +97,9 @@ class Runner { const int32_t vocab_size_; const int32_t max_seq_len_; int32_t eval_mode_; - std::vector> modules_; + std::vector< + std::shared_ptr> + modules_; std::vector method_names_; std::string tokenizer_path_; float temperature_; diff --git a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp index 585d58b21ee..90091c3b870 100644 --- a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp +++ b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp @@ -23,8 +23,8 @@ #include using executorch::extension::from_blob; -using executorch::extension::Module; using executorch::extension::TensorPtr; +using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; using executorch::runtime::MethodMeta; diff --git a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h index e49201bca25..df37e4829bd 100644 --- a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h +++ b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h @@ -111,7 +111,9 @@ class Runner { private: Stats stats_; - std::vector> modules_; + std::vector< + std::unique_ptr> + modules_; std::vector method_names_; std::vector> time_emb_list_; std::unordered_map vocab_to_token_map_; diff --git a/extension/android/jni/jni_layer.cpp b/extension/android/jni/jni_layer.cpp index f3c62e1d70f..ebbd3780c39 100644 --- a/extension/android/jni/jni_layer.cpp +++ b/extension/android/jni/jni_layer.cpp @@ -36,6 +36,7 @@ using namespace executorch::extension; using namespace torch::executor; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; namespace executorch::extension { class TensorHybrid : public facebook::jni::HybridClass { diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm index 98f0f555991..414fba7dc13 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm @@ -15,6 +15,7 @@ using namespace executorch::extension; using namespace executorch::runtime; +using namespace executorch::extension::ET_MODULE_NAMESPACE::Module; static inline EValue toEValue(ExecuTorchValue *value) { if (value.isTensor) { diff --git a/extension/llm/runner/image_prefiller.h b/extension/llm/runner/image_prefiller.h index 826cea24db9..aaca29fb5f0 100644 --- a/extension/llm/runner/image_prefiller.h +++ b/extension/llm/runner/image_prefiller.h @@ -14,6 +14,8 @@ #include #include +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; + namespace executorch { namespace extension { namespace llm { @@ -21,7 +23,8 @@ namespace llm { // Assuming kv cache and parallel prefill are enabled. class ET_EXPERIMENTAL ImagePrefiller { public: - explicit ImagePrefiller(::executorch::extension::Module* module) + explicit ImagePrefiller( + ::executorch::extension::ET_MODULE_NAMESPACE::Module* module) : module_(module) {} /** diff --git a/extension/llm/runner/multimodal_runner.h b/extension/llm/runner/multimodal_runner.h index c17e039c11b..fc66e56553d 100644 --- a/extension/llm/runner/multimodal_runner.h +++ b/extension/llm/runner/multimodal_runner.h @@ -29,6 +29,8 @@ #include #include +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; + namespace executorch { namespace extension { namespace llm { diff --git a/extension/llm/runner/text_decoder_runner.h b/extension/llm/runner/text_decoder_runner.h index 6c1256c6b90..7f40a7efae0 100644 --- a/extension/llm/runner/text_decoder_runner.h +++ b/extension/llm/runner/text_decoder_runner.h @@ -15,6 +15,8 @@ #include #include +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; + namespace executorch { namespace extension { namespace llm { diff --git a/extension/module/module.cpp b/extension/module/module.cpp index ec01323edc7..2bab588569f 100644 --- a/extension/module/module.cpp +++ b/extension/module/module.cpp @@ -36,6 +36,7 @@ namespace executorch { namespace extension { +namespace ET_MODULE_NAMESPACE { using ET_RUNTIME_NAMESPACE::MethodMeta; using ET_RUNTIME_NAMESPACE::Program; @@ -312,5 +313,6 @@ ET_NODISCARD inline runtime::Result Module::get_method( return methods_[method_name].method.get(); } +} // namespace ET_MODULE_NAMESPACE } // namespace extension } // namespace executorch diff --git a/extension/module/module.h b/extension/module/module.h index 201887b9ccc..46e35dd7ca5 100644 --- a/extension/module/module.h +++ b/extension/module/module.h @@ -16,8 +16,15 @@ #include +#ifdef USE_ATEN_LIB +#define ET_MODULE_NAMESPACE module::aten +#else // !USE_ATEN_LIB +#define ET_MODULE_NAMESPACE module +#endif // USE_ATEN_LIB + namespace executorch { namespace extension { +namespace ET_MODULE_NAMESPACE { using ET_RUNTIME_NAMESPACE::Method; using ET_RUNTIME_NAMESPACE::MethodMeta; @@ -506,6 +513,7 @@ class Module { friend class ExecuTorchJni; }; +} // namespace ET_MODULE_NAMESPACE } // namespace extension } // namespace executorch @@ -513,6 +521,6 @@ namespace torch { namespace executor { // TODO(T197294990): Remove these deprecated aliases once all users have moved // to the new `::executorch` namespaces. -using ::executorch::extension::Module; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; } // namespace executor } // namespace torch diff --git a/extension/module/test/module_test.cpp b/extension/module/test/module_test.cpp index a82e257a703..472af2cecdb 100644 --- a/extension/module/test/module_test.cpp +++ b/extension/module/test/module_test.cpp @@ -18,6 +18,7 @@ using namespace ::executorch::extension; using namespace ::executorch::runtime; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; class ModuleTest : public ::testing::Test { protected: diff --git a/extension/training/module/training_module.cpp b/extension/training/module/training_module.cpp index d119738715e..6b3015a9d79 100644 --- a/extension/training/module/training_module.cpp +++ b/extension/training/module/training_module.cpp @@ -25,7 +25,8 @@ TrainingModule::execute_forward_backward( // Find where the user outputs end. const std::string gradients_method_name = gradients_method_prefix + method_name; - auto res = executorch::extension::Module::execute(gradients_method_name); + auto res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( + gradients_method_name); if (!res.ok()) { return res.error(); } @@ -34,8 +35,8 @@ TrainingModule::execute_forward_backward( const std::string parameters_method_name = parameters_method_prefix + method_name; // get params start. - auto param_res = - executorch::extension::Module::execute(parameters_method_name); + auto param_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( + parameters_method_name); if (!param_res.ok()) { return param_res.error(); } @@ -67,7 +68,8 @@ TrainingModule::execute_forward_backward( // Get names if we havent seen this method before. const std::string fqn_method_name = fqn_method_prefix + method_name; - auto fqn_res = executorch::extension::Module::execute(fqn_method_name); + auto fqn_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( + fqn_method_name); if (!fqn_res.ok()) { return fqn_res.error(); } @@ -100,7 +102,8 @@ TrainingModule::named_parameters(const std::string& method_name) { method_named_parameters_.insert({method_name, {}}); // get names. - auto fqn_res = executorch::extension::Module::execute(fqn_method_name); + auto fqn_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( + fqn_method_name); if (!fqn_res.ok()) { return fqn_res.error(); } @@ -108,7 +111,8 @@ TrainingModule::named_parameters(const std::string& method_name) { // get params start. auto param_res = - executorch::extension::Module::execute(parameters_method_name); + executorch::extension::ET_MODULE_NAMESPACE::Module::execute( + parameters_method_name); if (!param_res.ok()) { return param_res.error(); } @@ -116,7 +120,8 @@ TrainingModule::named_parameters(const std::string& method_name) { uint64_t param_start = param_res.get()[0].toInt(); // Load the method if it is not already loaded. - auto e = executorch::extension::Module::load_method(method_name); + auto e = executorch::extension::ET_MODULE_NAMESPACE::Module::load_method( + method_name); if (e != runtime::Error::Ok) { return e; } diff --git a/extension/training/module/training_module.h b/extension/training/module/training_module.h index 7bf81623c04..1d48355b7ba 100644 --- a/extension/training/module/training_module.h +++ b/extension/training/module/training_module.h @@ -27,7 +27,7 @@ namespace training { * methods within them. */ class ET_EXPERIMENTAL TrainingModule final - : public executorch::extension::Module { + : public executorch::extension::ET_MODULE_NAMESPACE::Module { public: explicit TrainingModule( std::unique_ptr data_loader, @@ -35,7 +35,7 @@ class ET_EXPERIMENTAL TrainingModule final std::unique_ptr temp_allocator = nullptr, std::unique_ptr event_tracer = nullptr, std::unique_ptr data_map_data_loader = nullptr) - : executorch::extension::Module( + : executorch::extension::ET_MODULE_NAMESPACE::Module( std::move(data_loader), std::move(memory_allocator), std::move(temp_allocator), From 89c020d154abf27e7ade0c4d864965b527af08e0 Mon Sep 17 00:00:00 2001 From: zhenyan-zhang-meta Date: Wed, 30 Apr 2025 00:29:39 -0700 Subject: [PATCH 2/3] Update on "[ExecuTorch] Separate `extension.Module` Namespaces from Aten and non-Aten" Separate `extension.Module` Namespaces to be `executorch::extension::module` and `executorch::extension::module_aten`, otherwise in the future there will be issues like P1799454769. It's similar to what we already did for bundled_program in https://github.com/pytorch/executorch/pull/10307 Differential Revision: [D73903870](https://our.internmc.facebook.com/intern/diff/D73903870/) [ghstack-poisoned] --- docs/source/extension-module.md | 2 -- docs/source/extension-tensor.md | 2 -- docs/source/getting-started.md | 1 - docs/source/llm/getting-started.md | 2 +- docs/source/using-executorch-cpp.md | 1 - examples/llm_manual/main.cpp | 2 +- examples/models/llama/runner/runner.cpp | 2 +- examples/models/llama/runner/runner.h | 2 +- .../llava/runner/llava_image_prefiller.h | 3 +-- .../llava/runner/llava_text_decoder_runner.h | 3 +-- examples/models/phi-3-mini/runner.cpp | 2 +- examples/models/phi-3-mini/runner.h | 2 +- .../oss_scripts/llama/runner/io_manager.cpp | 2 +- .../oss_scripts/llama/runner/io_manager.h | 16 +++++----------- .../oss_scripts/llama/runner/runner.cpp | 2 +- .../oss_scripts/llama/runner/runner.h | 4 +--- .../qaihub_scripts/llama/runner/io_memory.cpp | 2 +- .../qaihub_scripts/llama/runner/io_memory.h | 16 ++++------------ .../qaihub_scripts/llama/runner/runner.cpp | 2 +- .../qaihub_scripts/llama/runner/runner.h | 4 +--- .../stable_diffusion/runner/runner.cpp | 2 +- .../stable_diffusion/runner/runner.h | 4 +--- extension/android/jni/jni_layer.cpp | 1 - .../ExecuTorch/Exported/ExecuTorchModule.mm | 1 - extension/llm/runner/image_prefiller.h | 5 +---- extension/llm/runner/multimodal_runner.h | 2 -- extension/llm/runner/text_decoder_runner.h | 2 -- extension/module/module.cpp | 2 -- extension/module/module.h | 7 +++++++ extension/module/test/module_test.cpp | 1 - extension/training/module/training_module.cpp | 19 +++++++------------ extension/training/module/training_module.h | 4 ++-- 32 files changed, 42 insertions(+), 80 deletions(-) diff --git a/docs/source/extension-module.md b/docs/source/extension-module.md index d5bcddf9a65..835c5c12e27 100644 --- a/docs/source/extension-module.md +++ b/docs/source/extension-module.md @@ -13,7 +13,6 @@ Let's see how we can run the `SimpleConv` model generated from the [Exporting to #include using namespace ::executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Create a Module. Module module("/path/to/model.pte"); @@ -222,7 +221,6 @@ Use [ExecuTorch Dump](etdump.md) to trace model execution. Create an `ETDumpGen` #include using namespace ::executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; Module module("/path/to/model.pte", Module::LoadMode::MmapUseMlock, std::make_unique()); diff --git a/docs/source/extension-tensor.md b/docs/source/extension-tensor.md index fdfc72a2227..910c06053ed 100644 --- a/docs/source/extension-tensor.md +++ b/docs/source/extension-tensor.md @@ -11,7 +11,6 @@ Imagine you’re working with a [`Module`](extension-module.md) interface, and y using namespace executorch::aten; using namespace executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; SizesType sizes[] = {2, 3}; DimOrderType dim_order[] = {0, 1}; @@ -43,7 +42,6 @@ Here’s how you can use it: #include using namespace executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; auto tensor = make_tensor_ptr( {2, 3}, // sizes diff --git a/docs/source/getting-started.md b/docs/source/getting-started.md index a2c64d07663..b7a97190b49 100644 --- a/docs/source/getting-started.md +++ b/docs/source/getting-started.md @@ -194,7 +194,6 @@ Loading and running a model using the high-level API can be done as follows: #include using namespace ::executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Load the model. Module module("/path/to/model.pte"); diff --git a/docs/source/llm/getting-started.md b/docs/source/llm/getting-started.md index 522529a1eac..152162841e4 100644 --- a/docs/source/llm/getting-started.md +++ b/docs/source/llm/getting-started.md @@ -209,7 +209,7 @@ Create a file called main.cpp with the following contents: using executorch::aten::ScalarType; using executorch::aten::Tensor; using executorch::extension::from_blob; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::runtime::EValue; using executorch::runtime::Result; ``` diff --git a/docs/source/using-executorch-cpp.md b/docs/source/using-executorch-cpp.md index 46c0c15c39b..d64dad97da9 100644 --- a/docs/source/using-executorch-cpp.md +++ b/docs/source/using-executorch-cpp.md @@ -13,7 +13,6 @@ In addition the Module class, the tensor extension provides an encapsulated inte #include using namespace ::executorch::extension; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; // Load the model. Module module("/path/to/model.pte"); diff --git a/examples/llm_manual/main.cpp b/examples/llm_manual/main.cpp index a1ae207db96..76492513f91 100644 --- a/examples/llm_manual/main.cpp +++ b/examples/llm_manual/main.cpp @@ -20,7 +20,7 @@ using executorch::aten::ScalarType; using executorch::aten::Tensor; using executorch::extension::from_blob; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::runtime::EValue; using executorch::runtime::Result; diff --git a/examples/models/llama/runner/runner.cpp b/examples/models/llama/runner/runner.cpp index c6df62658fd..186c2013616 100644 --- a/examples/models/llama/runner/runner.cpp +++ b/examples/models/llama/runner/runner.cpp @@ -21,7 +21,7 @@ namespace example { -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; +using ::executorch::extension::Module; using ::executorch::runtime::Error; using ::executorch::runtime::Result; diff --git a/examples/models/llama/runner/runner.h b/examples/models/llama/runner/runner.h index 9cc9deaf586..97ffe4b98b7 100644 --- a/examples/models/llama/runner/runner.h +++ b/examples/models/llama/runner/runner.h @@ -60,7 +60,7 @@ class ET_EXPERIMENTAL Runner : public executorch::extension::llm::IRunner { bool shouldStop_{false}; // model - std::unique_ptr<::executorch::extension::ET_MODULE_NAMESPACE::Module> module_; + std::unique_ptr<::executorch::extension::Module> module_; std::string tokenizer_path_; std::unique_ptr<::tokenizers::Tokenizer> tokenizer_; std::unordered_map metadata_; diff --git a/examples/models/llava/runner/llava_image_prefiller.h b/examples/models/llava/runner/llava_image_prefiller.h index aa377d1528d..762a28d0d07 100644 --- a/examples/models/llava/runner/llava_image_prefiller.h +++ b/examples/models/llava/runner/llava_image_prefiller.h @@ -18,8 +18,7 @@ namespace example { class ET_EXPERIMENTAL LlavaImagePrefiller : public ::executorch::extension::llm::ImagePrefiller { public: - explicit LlavaImagePrefiller( - ::executorch::extension::ET_MODULE_NAMESPACE::Module* module) + explicit LlavaImagePrefiller(::executorch::extension::Module* module) : ImagePrefiller(module){}; /** * Prefill an LLM Module with the given image input. diff --git a/examples/models/llava/runner/llava_text_decoder_runner.h b/examples/models/llava/runner/llava_text_decoder_runner.h index cbec7dd927d..3de418b57ea 100644 --- a/examples/models/llava/runner/llava_text_decoder_runner.h +++ b/examples/models/llava/runner/llava_text_decoder_runner.h @@ -17,8 +17,7 @@ namespace example { class ET_EXPERIMENTAL LlavaTextDecoderRunner : public executorch::extension::llm::TextDecoderRunner { public: - explicit LlavaTextDecoderRunner( - executorch::extension::ET_MODULE_NAMESPACE::Module* module) + explicit LlavaTextDecoderRunner(executorch::extension::Module* module) : TextDecoderRunner(module, true) {} inline executorch::runtime::Result step( diff --git a/examples/models/phi-3-mini/runner.cpp b/examples/models/phi-3-mini/runner.cpp index 8b5457c62ec..15f76e9522c 100644 --- a/examples/models/phi-3-mini/runner.cpp +++ b/examples/models/phi-3-mini/runner.cpp @@ -16,7 +16,7 @@ #include using executorch::aten::ScalarType; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::extension::llm::Sampler; using executorch::runtime::Error; using tokenizers::Llama2cTokenizer; diff --git a/examples/models/phi-3-mini/runner.h b/examples/models/phi-3-mini/runner.h index fcb6cd71efa..2f0042a57ea 100644 --- a/examples/models/phi-3-mini/runner.h +++ b/examples/models/phi-3-mini/runner.h @@ -42,7 +42,7 @@ class Runner { uint64_t prefill(std::vector& tokens); uint64_t run_model_step(uint64_t token); - std::unique_ptr module_; + std::unique_ptr module_; std::unique_ptr tokenizer_; std::unique_ptr sampler_; }; diff --git a/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp b/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp index 8bdcc462923..c2bf7b04fbb 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp +++ b/examples/qualcomm/oss_scripts/llama/runner/io_manager.cpp @@ -12,7 +12,7 @@ using executorch::aten::Tensor; using executorch::aten::TensorImpl; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::runtime::Error; using executorch::runtime::MemoryAllocator; using executorch::runtime::MethodMeta; diff --git a/examples/qualcomm/oss_scripts/llama/runner/io_manager.h b/examples/qualcomm/oss_scripts/llama/runner/io_manager.h index 5a305fa7406..0f10eef8ddc 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/io_manager.h +++ b/examples/qualcomm/oss_scripts/llama/runner/io_manager.h @@ -20,8 +20,6 @@ #include #include -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; - namespace example { enum EvalMode { @@ -31,8 +29,8 @@ enum EvalMode { }; class IoMgrBase { public: - IoMgrBase(std::vector>& modules); + IoMgrBase( + std::vector>& modules); virtual ~IoMgrBase(); virtual void init_io() = 0; virtual void reset_io( @@ -83,16 +81,13 @@ class IoMgrBase { std::string, std::vector>> output_tensors_; - std::vector< - std::shared_ptr> - modules_; + std::vector> modules_; }; class ShiftPointerIoMgr : public IoMgrBase { public: ShiftPointerIoMgr( - std::vector>& modules, + std::vector>& modules, int32_t context_len, int32_t prefill_ar_len, int32_t prefill_cache_len, @@ -204,8 +199,7 @@ class ShiftPointerIoMgr : public IoMgrBase { class SmartMaskIoMgr : public IoMgrBase { public: SmartMaskIoMgr( - std::vector>& modules, + std::vector>& modules, int32_t context_len, int32_t prefill_ar_len, int32_t prefill_cache_len, diff --git a/examples/qualcomm/oss_scripts/llama/runner/runner.cpp b/examples/qualcomm/oss_scripts/llama/runner/runner.cpp index 7e7c48a517e..dafc911a172 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/runner.cpp +++ b/examples/qualcomm/oss_scripts/llama/runner/runner.cpp @@ -23,7 +23,7 @@ #include using executorch::aten::Tensor; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::extension::llm::Sampler; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; diff --git a/examples/qualcomm/oss_scripts/llama/runner/runner.h b/examples/qualcomm/oss_scripts/llama/runner/runner.h index 93c3440a503..e693bcd7077 100644 --- a/examples/qualcomm/oss_scripts/llama/runner/runner.h +++ b/examples/qualcomm/oss_scripts/llama/runner/runner.h @@ -101,9 +101,7 @@ class Runner { std::unordered_set eos_id_; const int32_t n_bos_; const int32_t n_eos_; - std::vector< - std::shared_ptr> - modules_; + std::vector> modules_; std::string tokenizer_path_; std::string performance_output_path_; float logits_scale_; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp index 8a5ddcd7ded..9ee7551650a 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp +++ b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.cpp @@ -14,7 +14,7 @@ using executorch::aten::Tensor; using executorch::aten::TensorImpl; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::runtime::Error; using executorch::runtime::MethodMeta; using executorch::runtime::Result; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h index 012f40404b4..445be2ed21a 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h +++ b/examples/qualcomm/qaihub_scripts/llama/runner/io_memory.h @@ -32,9 +32,7 @@ class Memory { public: Memory( const std::vector& pos_embs_path, - std::vector< - std::shared_ptr>& - modules); + std::vector>& modules); virtual ~Memory(); virtual void prepare_io( const std::vector< @@ -53,9 +51,7 @@ class Memory { std::vector> input_tensors_; std::vector> output_tensors_; std::vector pos_embs_path_; - std::vector< - std::shared_ptr> - modules_; + std::vector> modules_; std::vector method_names_; }; @@ -63,9 +59,7 @@ class BertMemory : public Memory { public: BertMemory( const std::vector& pos_embs_path, - std::vector< - std::shared_ptr>& - modules, + std::vector>& modules, std::vector shard_layers); void prepare_io(const std::vector>& methods_meta) override; @@ -127,9 +121,7 @@ class KVCachedMemory : public Memory { public: KVCachedMemory( const std::vector& pos_embs_path, - std::vector< - std::shared_ptr>& - modules, + std::vector>& modules, std::vector shard_layers); void prepare_io(const std::vector>& methods_meta) override; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp b/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp index cb98fcf04f3..06ea324ef6f 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp +++ b/examples/qualcomm/qaihub_scripts/llama/runner/runner.cpp @@ -30,7 +30,7 @@ #endif using executorch::aten::Tensor; -using executorch::extension::ET_MODULE_NAMESPACE::Module; +using executorch::extension::Module; using executorch::extension::llm::Sampler; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; diff --git a/examples/qualcomm/qaihub_scripts/llama/runner/runner.h b/examples/qualcomm/qaihub_scripts/llama/runner/runner.h index effd2ca8c50..9672d6a3586 100644 --- a/examples/qualcomm/qaihub_scripts/llama/runner/runner.h +++ b/examples/qualcomm/qaihub_scripts/llama/runner/runner.h @@ -97,9 +97,7 @@ class Runner { const int32_t vocab_size_; const int32_t max_seq_len_; int32_t eval_mode_; - std::vector< - std::shared_ptr> - modules_; + std::vector> modules_; std::vector method_names_; std::string tokenizer_path_; float temperature_; diff --git a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp index 90091c3b870..585d58b21ee 100644 --- a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp +++ b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.cpp @@ -23,8 +23,8 @@ #include using executorch::extension::from_blob; +using executorch::extension::Module; using executorch::extension::TensorPtr; -using executorch::extension::ET_MODULE_NAMESPACE::Module; using executorch::extension::llm::time_in_ms; using executorch::runtime::Error; using executorch::runtime::MethodMeta; diff --git a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h index df37e4829bd..e49201bca25 100644 --- a/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h +++ b/examples/qualcomm/qaihub_scripts/stable_diffusion/runner/runner.h @@ -111,9 +111,7 @@ class Runner { private: Stats stats_; - std::vector< - std::unique_ptr> - modules_; + std::vector> modules_; std::vector method_names_; std::vector> time_emb_list_; std::unordered_map vocab_to_token_map_; diff --git a/extension/android/jni/jni_layer.cpp b/extension/android/jni/jni_layer.cpp index ebbd3780c39..f3c62e1d70f 100644 --- a/extension/android/jni/jni_layer.cpp +++ b/extension/android/jni/jni_layer.cpp @@ -36,7 +36,6 @@ using namespace executorch::extension; using namespace torch::executor; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; namespace executorch::extension { class TensorHybrid : public facebook::jni::HybridClass { diff --git a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm index 414fba7dc13..98f0f555991 100644 --- a/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm +++ b/extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm @@ -15,7 +15,6 @@ using namespace executorch::extension; using namespace executorch::runtime; -using namespace executorch::extension::ET_MODULE_NAMESPACE::Module; static inline EValue toEValue(ExecuTorchValue *value) { if (value.isTensor) { diff --git a/extension/llm/runner/image_prefiller.h b/extension/llm/runner/image_prefiller.h index aaca29fb5f0..826cea24db9 100644 --- a/extension/llm/runner/image_prefiller.h +++ b/extension/llm/runner/image_prefiller.h @@ -14,8 +14,6 @@ #include #include -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; - namespace executorch { namespace extension { namespace llm { @@ -23,8 +21,7 @@ namespace llm { // Assuming kv cache and parallel prefill are enabled. class ET_EXPERIMENTAL ImagePrefiller { public: - explicit ImagePrefiller( - ::executorch::extension::ET_MODULE_NAMESPACE::Module* module) + explicit ImagePrefiller(::executorch::extension::Module* module) : module_(module) {} /** diff --git a/extension/llm/runner/multimodal_runner.h b/extension/llm/runner/multimodal_runner.h index fc66e56553d..c17e039c11b 100644 --- a/extension/llm/runner/multimodal_runner.h +++ b/extension/llm/runner/multimodal_runner.h @@ -29,8 +29,6 @@ #include #include -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; - namespace executorch { namespace extension { namespace llm { diff --git a/extension/llm/runner/text_decoder_runner.h b/extension/llm/runner/text_decoder_runner.h index 7f40a7efae0..6c1256c6b90 100644 --- a/extension/llm/runner/text_decoder_runner.h +++ b/extension/llm/runner/text_decoder_runner.h @@ -15,8 +15,6 @@ #include #include -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; - namespace executorch { namespace extension { namespace llm { diff --git a/extension/module/module.cpp b/extension/module/module.cpp index 2bab588569f..ec01323edc7 100644 --- a/extension/module/module.cpp +++ b/extension/module/module.cpp @@ -36,7 +36,6 @@ namespace executorch { namespace extension { -namespace ET_MODULE_NAMESPACE { using ET_RUNTIME_NAMESPACE::MethodMeta; using ET_RUNTIME_NAMESPACE::Program; @@ -313,6 +312,5 @@ ET_NODISCARD inline runtime::Result Module::get_method( return methods_[method_name].method.get(); } -} // namespace ET_MODULE_NAMESPACE } // namespace extension } // namespace executorch diff --git a/extension/module/module.h b/extension/module/module.h index 46e35dd7ca5..4f8d4ea784d 100644 --- a/extension/module/module.h +++ b/extension/module/module.h @@ -524,3 +524,10 @@ namespace executor { using ::executorch::extension::ET_MODULE_NAMESPACE::Module; } // namespace executor } // namespace torch + +namespace executorch { +namespace extension { +// backward compatible namespace alias +using namespace ::executorch::extension::ET_MODULE_NAMESPACE; +} // namespace extension +} // namespace executorch diff --git a/extension/module/test/module_test.cpp b/extension/module/test/module_test.cpp index 472af2cecdb..a82e257a703 100644 --- a/extension/module/test/module_test.cpp +++ b/extension/module/test/module_test.cpp @@ -18,7 +18,6 @@ using namespace ::executorch::extension; using namespace ::executorch::runtime; -using ::executorch::extension::ET_MODULE_NAMESPACE::Module; class ModuleTest : public ::testing::Test { protected: diff --git a/extension/training/module/training_module.cpp b/extension/training/module/training_module.cpp index 6b3015a9d79..d119738715e 100644 --- a/extension/training/module/training_module.cpp +++ b/extension/training/module/training_module.cpp @@ -25,8 +25,7 @@ TrainingModule::execute_forward_backward( // Find where the user outputs end. const std::string gradients_method_name = gradients_method_prefix + method_name; - auto res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( - gradients_method_name); + auto res = executorch::extension::Module::execute(gradients_method_name); if (!res.ok()) { return res.error(); } @@ -35,8 +34,8 @@ TrainingModule::execute_forward_backward( const std::string parameters_method_name = parameters_method_prefix + method_name; // get params start. - auto param_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( - parameters_method_name); + auto param_res = + executorch::extension::Module::execute(parameters_method_name); if (!param_res.ok()) { return param_res.error(); } @@ -68,8 +67,7 @@ TrainingModule::execute_forward_backward( // Get names if we havent seen this method before. const std::string fqn_method_name = fqn_method_prefix + method_name; - auto fqn_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( - fqn_method_name); + auto fqn_res = executorch::extension::Module::execute(fqn_method_name); if (!fqn_res.ok()) { return fqn_res.error(); } @@ -102,8 +100,7 @@ TrainingModule::named_parameters(const std::string& method_name) { method_named_parameters_.insert({method_name, {}}); // get names. - auto fqn_res = executorch::extension::ET_MODULE_NAMESPACE::Module::execute( - fqn_method_name); + auto fqn_res = executorch::extension::Module::execute(fqn_method_name); if (!fqn_res.ok()) { return fqn_res.error(); } @@ -111,8 +108,7 @@ TrainingModule::named_parameters(const std::string& method_name) { // get params start. auto param_res = - executorch::extension::ET_MODULE_NAMESPACE::Module::execute( - parameters_method_name); + executorch::extension::Module::execute(parameters_method_name); if (!param_res.ok()) { return param_res.error(); } @@ -120,8 +116,7 @@ TrainingModule::named_parameters(const std::string& method_name) { uint64_t param_start = param_res.get()[0].toInt(); // Load the method if it is not already loaded. - auto e = executorch::extension::ET_MODULE_NAMESPACE::Module::load_method( - method_name); + auto e = executorch::extension::Module::load_method(method_name); if (e != runtime::Error::Ok) { return e; } diff --git a/extension/training/module/training_module.h b/extension/training/module/training_module.h index 1d48355b7ba..7bf81623c04 100644 --- a/extension/training/module/training_module.h +++ b/extension/training/module/training_module.h @@ -27,7 +27,7 @@ namespace training { * methods within them. */ class ET_EXPERIMENTAL TrainingModule final - : public executorch::extension::ET_MODULE_NAMESPACE::Module { + : public executorch::extension::Module { public: explicit TrainingModule( std::unique_ptr data_loader, @@ -35,7 +35,7 @@ class ET_EXPERIMENTAL TrainingModule final std::unique_ptr temp_allocator = nullptr, std::unique_ptr event_tracer = nullptr, std::unique_ptr data_map_data_loader = nullptr) - : executorch::extension::ET_MODULE_NAMESPACE::Module( + : executorch::extension::Module( std::move(data_loader), std::move(memory_allocator), std::move(temp_allocator), From 064462747307f191fc90c32fe002d3ea15b344c0 Mon Sep 17 00:00:00 2001 From: zhenyan-zhang-meta Date: Wed, 30 Apr 2025 11:18:35 -0700 Subject: [PATCH 3/3] Update on "[ExecuTorch] Separate `extension.Module` Namespaces from Aten and non-Aten" # Context Separate `extension.Module` Namespaces to be `executorch::extension::module` and `executorch::extension::module::aten`, otherwise if a package relies on both aten and non-aten of the same implementation and the namespace is the same, there will be duplicate symbol issue like: ``` ld.lld: error: duplicate symbol: vtable for executorch::extension::Module >>> defined at {redacted}/executorch/extension/module/__module__/__stripped__/module.cpp.pic.stripped.o:(vtable for executorch::extension::Module) >>> defined at {redacted}/executorch/extension/module/__module_aten__/__stripped__/module.cpp.pic.stripped.o: ``` # Proposal Doing something similar to what we already did for `bundled_program` in https://github.com/pytorch/executorch/pull/10307 Since `extension.Module` is a public API, we introduce a namespace alias, so that existing use cases won't get affected. Since namespace alias doesn't create additional symbols, there won't be duplicate symbol issue. Differential Revision: [D73903870](https://our.internmc.facebook.com/intern/diff/D73903870/) [ghstack-poisoned] --- extension/module/module.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extension/module/module.h b/extension/module/module.h index 4f8d4ea784d..afd2fa47973 100644 --- a/extension/module/module.h +++ b/extension/module/module.h @@ -24,13 +24,16 @@ namespace executorch { namespace extension { -namespace ET_MODULE_NAMESPACE { using ET_RUNTIME_NAMESPACE::Method; using ET_RUNTIME_NAMESPACE::MethodMeta; using ET_RUNTIME_NAMESPACE::NamedDataMap; using ET_RUNTIME_NAMESPACE::Program; +class ExecuTorchJni; + +namespace ET_MODULE_NAMESPACE { + /** * A facade class for loading programs and executing methods within them. */ @@ -510,7 +513,7 @@ class Module { const std::string& method_name); std::unordered_map methods_; - friend class ExecuTorchJni; + friend class executorch::extension::ExecuTorchJni; }; } // namespace ET_MODULE_NAMESPACE @@ -528,6 +531,6 @@ using ::executorch::extension::ET_MODULE_NAMESPACE::Module; namespace executorch { namespace extension { // backward compatible namespace alias -using namespace ::executorch::extension::ET_MODULE_NAMESPACE; +using ::executorch::extension::ET_MODULE_NAMESPACE::Module; } // namespace extension } // namespace executorch