Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant generate &[u8] slice for ConfigProto to SessionOptions::set_config() #393

Open
Corallus-Caninus opened this issue Jan 18, 2023 · 4 comments

Comments

@Corallus-Caninus
Copy link
Contributor

I am not familiar with protobuff enough to generate my own messages. The Documentation mentions this but just references the C++ API and not protobuff examples or Rust ways to generate this. I noticed src/protos/config.rs has some protobuff stuff (ConfigProto) that might have a trait to generate &[u8] or cast a Message type to aligned bytes to generate &[u8] but its private. Got any pointers or references?

@dskkato
Copy link
Contributor

dskkato commented Jan 22, 2023

Within the crate code, for example, you can serialize message as follow:

rust/src/eager/context.rs

Lines 145 to 149 in 3f3f618

let mut config = ConfigProto::new();
config.set_gpu_options(gpu_options);
let mut buf = vec![];
config.write_to_writer(&mut buf).unwrap();

On top of that, it seems to be impossible to use the above code from outside the crate since the proto module is private as you pointed. We need to make the proto module public.

@Corallus-Caninus
Copy link
Contributor Author

Are we planning to build an abstraction or wrapper on top of proto? If not I can patch this.

@dskkato
Copy link
Contributor

dskkato commented Jan 25, 2023

@Corallus-Caninus

I can't immediately answer whether the proto module should be public. For example, the above method I tried in a unit test can be generated in Python as follows:

from tensorflow.core.protobuf.config_pb2 import ConfigProto, GPUOptions

gpu_options = GPUOptions(
    per_process_gpu_memory_fraction=0.5
    )

config = ConfigProto(gpu_options=gpu_options)

with open("config.protobuf", "wb") as f:
    f.write(config.SerializeToString())

Making proto module public may take time for some reason, so please try the above method.

@adamcrume
Copy link
Contributor

I've avoided exposing the generated proto code so far because that would lock in a choice of protobuf libraries, and it wasn't clear which protobuf crate was going to "win". We might have to bite the bullet at some point, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants