Stream: general

Topic: Accessing the path of a --mapdir


view this post on Zulip Brian Jones (Dec 02 2021 at 17:45):

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.

view this post on Zulip Till Schneidereit (Dec 02 2021 at 19:07):

CC @Dan Gohman

view this post on Zulip Dan Gohman (Dec 02 2021 at 19:10):

Is the problem that the path requires the --mapdir mapping to resolve, and you need that on the host side?

view this post on Zulip Brian Jones (Dec 03 2021 at 00:51):

Correct. I need the mapdir mapping to resolve on the host side.

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:52):

Does wasi-nn have an API where it takes a filename?

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:53):

Or are you opening the file and feeding the data into wasi-nn manually?

view this post on Zulip Brian Jones (Dec 03 2021 at 00:54):

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

view this post on Zulip Brian Jones (Dec 03 2021 at 00:56):

that function requires a path, and I want to know how to properly (if possible) get that from a wasi-nn call

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:57):

ah, I see.

view this post on Zulip Brian Jones (Dec 03 2021 at 00:57):

Yeah if load could just take a byte array I would do it the same way we do for OpenVino

view this post on Zulip Brian Jones (Dec 03 2021 at 00:58):

Open on the client side and pass bytes to wasi-nn

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:58):

Yeah. And in the future, one could imagine passing in a bytestream to wasi-nn so that it could stream the data in.

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:59):

Stream it in directly from a network source, or something else. Filesystem paths tie things to the filesystem, which is so limiting ;-)

view this post on Zulip Brian Jones (Dec 03 2021 at 00:59):

absolutely :)

view this post on Zulip Dan Gohman (Dec 03 2021 at 00:59):

I don't think we currently have a way to do a mapdir mapping in host code.

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:00):

We could add one, but it's very tempting to see if we can find a way to do this without having to.

view this post on Zulip Brian Jones (Dec 03 2021 at 01:01):

I certainly understand it could potentially break some sandboxing rules

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:01):

Do you think tensorflow would be open to a PR adding an alternate form of load?

view this post on Zulip Brian Jones (Dec 03 2021 at 01:02):

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

view this post on Zulip Brian Jones (Dec 03 2021 at 01:02):

its not a complex function - so might not be hard to do (knock on wood)

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:05):

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

view this post on Zulip Brian Jones (Dec 03 2021 at 01:06):

Oh interesting, yeah that certainly wouldn't work otherwise

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:07):

Looks like load is a wrapper around a tensorflow_sys function

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:09):

Hrm. It calls TF_LoadSessionFromSavedModel

An Open Source Machine Learning Framework for Everyone - tensorflow/c_api.h at fc8adb4ad3245912a7d71290e240fe626bd271ff · tensorflow/tensorflow

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:13):

This is not going to be trivial. The path is a directory path, and tensorflow expects to find multiple files under that path.

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:16):

It's not just a byte array, it's a whole tree of different things.

view this post on Zulip Dan Gohman (Dec 03 2021 at 01:16):

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.

view this post on Zulip Brian Jones (Dec 03 2021 at 01:17):

Ah yes, its a path to a dir

view this post on Zulip Brian Jones (Dec 03 2021 at 01:17):

Sure thing thanks Dan

view this post on Zulip Dan Gohman (Dec 03 2021 at 20:44):

@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.

view this post on Zulip Dan Gohman (Dec 03 2021 at 20:45):

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.

view this post on Zulip Brian Jones (Dec 03 2021 at 21:03):

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?

view this post on Zulip Brian Jones (Dec 03 2021 at 21:19):

@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 :)

view this post on Zulip Dan Gohman (Dec 03 2021 at 21:21):

Yes, to clarify, it's ok to work on this :-)

view this post on Zulip Brian Jones (Dec 03 2021 at 21:23):

Excelent thanks agian


Last updated: Nov 22 2024 at 16:03 UTC