- Notifications
You must be signed in to change notification settings - Fork429
Rust language bindings for TensorFlow
License
tensorflow/rust
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TensorFlow Rust provides idiomaticRust languagebindings forTensorFlow.
Notice: This project is still under active development and not guaranteed to have astable API.
Since this crate depends on the TensorFlow C API, it needs to be downloaded or compiled first. Thiscrate will automatically download or compile the TensorFlow shared libraries for you, but it is alsopossible to manually install TensorFlow and the crate will pick it up accordingly.
If the TensorFlow shared libraries can already be found on your system, they will be used. If yoursystem is x86-64 Linux or Mac, a prebuilt binary will be downloaded, and no special prerequisitesare needed.
Otherwise, the following dependencies are needed to compile and build this crate, which involvescompiling TensorFlow itself:
- git
- bazel
- Python Dependencies
numpy
,dev
,pip
andwheel
- Optionally, CUDA packages to support GPU-based processing
The TensorFlow website provides detailed instructions on how to obtain and install said dependencies,so if you are unsure pleasecheck out the docsfor further details.
Some of the examples use TensorFlow code written in Python and require a full TensorFlowinstallation.
The minimum supported Rust version is 1.58.
Add this to yourCargo.toml
:
[dependencies]tensorflow ="0.21.0"
and this to your crate root:
externcrate tensorflow;
Then runcargo build -j 1
. The tensorflow-sys crate'sbuild.rs
now either downloads a pre-built, basic CPU only binary(the default)or compiles TensorFlow if forced to by an environment variable. If TensorFlowis compiled during this process, since the full compilation is very memoryintensive, we recommend using the-j 1
flag which tells cargo to use only onetask, which in turn tells TensorFlow to build with only one task. Though, ifyou have a lot of RAM, you can obviously use a higher value.
To include the especially unstable API (which is currently theexpr
module),use--features tensorflow_unstable
.
For now, please see theExamples for moredetails on how to use this binding.
When printing or debugging a tensor, it will print every element by default, thiscan be modified by changing an environment variable:
TF_RUST_DISPLAY_MAX=5
Which will truncate the values if they exceed the limit:
let values:Vec<u64> =(0..100000).collect();let t =Tensor::new(&[2,50000]).with_values(&values).unwrap();dbg!(t);
t = Tensor<u64> { values: [ [0, 1, 2, 3, 4, ...], ... ], dtype: uint64, shape: [2, 50000]}
To enable GPU support, use thetensorflow_gpu
feature in your Cargo.toml:
[dependencies]tensorflow = { version = "0.21.0", features = ["tensorflow_gpu"] }
If you want to work against unreleased/unsupported TensorFlow versions or use a build optimized foryour machine, manual compilation is the way to go.
Seetensorflow-sys/README.md for details.
The especially unstable parts of the API (which is currently theexpr
module) arefeature-gated behind the featuretensorflow_unstable
to prevent accidentaluse. Seehttp://doc.crates.io/manifest.html#the-features-section.(We would prefer using an#[unstable]
attribute, but thatdoesn't exist yet.)
Try thedocumentation first, and see if it answersyour question. If not, take a look at the examples folder. Note that there may not be an examplefor your exact question, but it may be answered by an example demonstrating something else.
If none of the above help, you can ask your question onTensorFlow Rust Google Group.
Developers and users are welcome to join theTensorFlow Rust Google Group.
Please read thecontribution guidelines on how to contribute code.
This is not an official Google product.
RFCs areissues tagged with RFC.Check them out and comment. Discussions are welcomed. After all, that is the purpose ofRequest For Comment!
This project is licensed under the terms of theApache 2.0 license.
About
Rust language bindings for TensorFlow