Skip to content

Commit 7517619

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
Expose a method getter api so
Summary: Module currently cannot compose with apis that operate directly on module. Exposing the method directly so that module can compose with these lower level apis. The first practical use case of this is io manager for llms. Differential Revision: D77248983
1 parent d5fe5fa commit 7517619

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

extension/module/module.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ runtime::Error Module::load_method(
228228
return runtime::Error::Ok;
229229
}
230230

231+
ET_NODISCARD inline runtime::Result<Method*> Module::method(
232+
const std::string& method_name) {
233+
ET_CHECK_OR_RETURN_ERROR(
234+
methods_.count(method_name) > 0,
235+
InvalidArgument,
236+
"no such method in program: %s",
237+
method_name.c_str());
238+
return methods_[method_name].method.get();
239+
}
240+
231241
runtime::Result<MethodMeta> Module::method_meta(
232242
const std::string& method_name) {
233243
ET_CHECK_OK_OR_RETURN_ERROR(load());

extension/module/module.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ class Module {
194194
return load_method(method_name, nullptr, event_tracer);
195195
}
196196

197+
/**
198+
* Get a method by it's name. Not recommended to use this method directly as an end user.
199+
* It's exposed to allow for composability of module in apis that operate on method.
200+
*
201+
* @param[in] method_name The name of the method to get.
202+
*
203+
* @returns A Result object containing either a pointer to the requested
204+
* method or an error to indicate failure.
205+
*/
206+
ET_NODISCARD inline runtime::Result<Method*> method(
207+
const std::string& method_name);
208+
197209
/**
198210
* Load the 'forward' method from the program and set up memory management if
199211
* needed. The loaded method is cached to reuse the next time it's executed.

0 commit comments

Comments
 (0)