Repository navigation
Add convenience functions to runtime bindings and disambiguate names - #5697
Conversation
|
Pytype added more advanced |
8618bcc to
2af73cf
Compare
| vm_instance: _binding.VmInstance | ||
| host_type_factory: _binding.HostTypeFactory | ||
| default_modules: Tuple[AnyModule] | ||
| default_vm_modules: Tuple[_binding.VmModule, ...] |
There was a problem hiding this comment.
Oh, thanks - I just ran into it and changed it to Sequence. But your way is better.
| # Mapping from IREE target backends to their corresponding drivers. | ||
| TARGET_BACKEND_TO_DRIVER = { | ||
| "vmla": "vmla", | ||
| "dylib-llvm-aot": "dylib", | ||
| "vulkan-*": "vulkan", |
There was a problem hiding this comment.
Why does the runtime component need such a mapping? The runtime should just operate on HAL drivers. Any compiler target could be used to produce compatible executables.
It's perfectly reasonable to write a new compiler target that produces executables for the dylib driver, and indirecting through a mapping like this in Python would make using that awkward (you'd have to piggyback off the existing "dylib-llvm-aot" target backend mapping).
There was a problem hiding this comment.
This is really just intended to be a temporary convenience function for people coming from python to be able to execute the model that they compile easily. A better solution here would be to detect compatible drivers for the provided VmModule, and default to one when the user doesn't specify any, or something similar to that.
In the meantime, I don't think we should require a ML dev who just wants to see if something runs to understand the relationship between target backends and drivers, and have a mental map of which target backends are compatible with which drivers. The names are similar, but I don't think it's obvious that you should specify dylib for dylib-llvm-aot or vulkan for vulkan-* on the face of it.
I could change the API of these two functions to allow for specifying both? e.g.:
def load_vm_flatbuffer*(artifact, *, driver: Optional[str]=None, backend: Optional[str]=None):
if driver is None and backend is None:
raise ValueError("Either 'driver' or 'backend' must be specified, but got 'None' for both.")
if backend is not None and driver is not None:
raise ValueError("Cannot specify both 'driver' and a 'backend' to infer the driver from.")
if backend is not None:
driver = TARGET_BACKEND_TO_DRIVER[backend]
...There was a problem hiding this comment.
Yeah, compiler targets and runtime HAL drivers are low level details that higher level abstractions can be built upon. Expecting users at the higher levels of the stack to work with them is asking a bit much.
I'm concerned about baking too many specific details into the API that are not accurate. There can be a many-to-many relationship between compiler targets and HAL drivers.
Designing towards a generic interface where the high level system just figures out the details on its own would be nice. Right now the Python bindings are pretty thinly layered on top of the C APIs, so these sorts of details keep showing up. I'd rather the bindings commit to either being low level or high level, rather than act low level in some areas then add helpers for certain types of tasks in others.
I'm not sure that specifically helps much here though. For now, what you suggest with accepting either a backend or a driver and trying to infer one from the other seems good enough. That would let users who know what they are doing have explicit control, while others could just lean on the defaults.
There was a problem hiding this comment.
Maybe it would be useful to have a thin frontend-agnostic compiler+runtime API that contains the utilities a high-level user would want (e.g. 'cute' names for target triple + driver configurations, named MLIR modules, ...)? That would allow iree.runtime be a low level API intended to be used by high-level users indirectly via frontend specific compiler+runtime APIs like iree.jax while also reducing code duplication between frontend specific APIs.
| def load_vm_flatbuffer(vm_flatbuffer: bytes, backend: str) -> BoundModule: | ||
| """Loads a VM Flatbuffer into a callable module.""" | ||
| vm_module = _binding.VmModule.from_flatbuffer(vm_flatbuffer) | ||
| config = Config(TARGET_BACKEND_TO_DRIVER[backend]) |
There was a problem hiding this comment.
Continuing from my comment above - this should just take driver: str without the extra lookup.
add_module was renamed to add_vm_module in #5697, so this PR updates the usage in colab
Add
iree.runtime.load_vm_flatbufferandiree.runtime.load_vm_flatbuffer_fileto make it easier to bind binaries produced byiree.compiler. e.g.:Also disambiguates
moduletovm_moduleinsystem_api.pywhere appropriate to reduce (my) confusion.