I'm adding another backend (Tensorflow) to the wasi-nn crate in Wasmtime. One of the calls it makes requires a path to some files the .wasm app is using. I can open the files fine on the client side using fs:read("mapdir_name"). But when I want to read those files on the Host side, I'm not clear on how to do this. More plainly, I have a web assembly example I'm running using --mapdir to specify where my files are located. I want the app to pass that mapped folder name to wasi-nn and be able to open the files on the wasi-nn side. Is this currently doable, and if so what is the best way to accomplish this? Thanks.
CC @Dan Gohman
Is the problem that the path requires the --mapdir mapping to resolve, and you need that on the host side?
Correct. I need the mapdir mapping to resolve on the host side.
Does wasi-nn have an API where it takes a filename?
Or are you opening the file and feeding the data into wasi-nn manually?
This is for a new wasi-nn backend, so new code. Specifically I'm trying to use this function 'load' https://tensorflow.github.io/rust/tensorflow/struct.SavedModelBundle.html#method.load
that function requires a path, and I want to know how to properly (if possible) get that from a wasi-nn call
ah, I see.
Yeah if load could just take a byte array I would do it the same way we do for OpenVino
Open on the client side and pass bytes to wasi-nn
Yeah. And in the future, one could imagine passing in a bytestream to wasi-nn so that it could stream the data in.
Stream it in directly from a network source, or something else. Filesystem paths tie things to the filesystem, which is so limiting ;-)
absolutely :)
I don't think we currently have a way to do a mapdir mapping in host code.
We could add one, but it's very tempting to see if we can find a way to do this without having to.
I certainly understand it could potentially break some sandboxing rules
Do you think tensorflow would be open to a PR adding an alternate form of load
?
I don't know, that was the alternative I discussed with Andrew. Pushing a PR that added a load that would accept a byte array
its not a complex function - so might not be hard to do (knock on wood)
Yeah. It would make the sandboxing situation much simpler, as well as the deployment situation. Some WASI environments don't have filesystems, such as Compute@Edge
Oh interesting, yeah that certainly wouldn't work otherwise
Looks like load
is a wrapper around a tensorflow_sys function
Hrm. It calls TF_LoadSessionFromSavedModel
This is not going to be trivial. The path is a directory path, and tensorflow expects to find multiple files under that path.
It's not just a byte array, it's a whole tree of different things.
Ok. I have to go offline now, but I'll be around tomorrow; if possible, let's sync up and talk about possible options here.
Ah yes, its a path to a dir
Sure thing thanks Dan
@Brian Jones I think what makes sense for the present is to add a way to get at the mapdir mappings in the host, for now.
I expect we'll eventually have better features for dealing with kind of thing, in wit-bindgen, but to get something up and running right now, just using the existing tooling, and the existing Tensorflow API, makes sense.
Ok sounds good. Is that something I can do and submit a PR? Or should I submit a bug/feature request and let the appropriate person handle it?
@Dan Gohman Oh sorry I read that a a little more carefully and sounds like its ok If work on this. Let me know if that's not the case, not trying to break things :)
Yes, to clarify, it's ok to work on this :-)
Excelent thanks agian
Last updated: Nov 22 2024 at 16:03 UTC