Overview of TensorFlow Rust
TensorFlow Rust is designed to provide idiomatic language bindings for TensorFlow in Rust. This enables developers to leverage the power and performance of Rust while making use of TensorFlow's machine learning capabilities. The project is still under active development, so users should note that the API might change over time.
Getting Started
Dependencies
To get started with TensorFlow Rust, one needs to meet certain prerequisites. If TensorFlow's shared libraries are already installed on your system, the crate will utilize them. For x86-64 Linux or Mac users, a prebuilt binary can be downloaded without additional prerequisites. However, if needed, the following tools should be set up:
- Git
- Bazel
- Python packages:
numpy
,dev
,pip
, andwheel
Optional CUDA packages may also be installed for GPU-based processing. For detailed dependency installation instructions, visit the TensorFlow installation documentation.
Installation
First, ensure that your Rust version is at least 1.58. For adding TensorFlow Rust, update your Cargo.toml
:
[dependencies]
tensorflow = "0.21.0"
Add to your Rust crate root:
extern crate tensorflow;
Then, compile the crate using cargo build -j 1
. This command downloads a pre-built basic CPU-only binary, or compiles TensorFlow if specified by an environment variable. It's memory-intensive, so using the -j 1
flag can help manage resource usage.
For those interested in more unstable parts of the API, include the expr
module using --features tensorflow_unstable
.
Additional Features
Tensor Maximum Display
When printing or debugging tensors, it displays every element by default. Users can adjust this by modifying an environment variable:
TF_RUST_DISPLAY_MAX=5
For instance, this will display only the first five elements:
let values: Vec<u64> = (0..100000).collect();
let t = Tensor::new(&[2, 50000]).with_values(&values).unwrap();
dbg!(t);
GPU Support
For GPU support, enable the tensorflow_gpu
feature in your Cargo.toml
:
[dependencies]
tensorflow = { version = "0.21.0", features = ["tensorflow_gpu"] }
Manual TensorFlow Compilation
Users wishing to work with unreleased TensorFlow versions or to create optimized builds for their machines can manually compile TensorFlow. For further instructions, refer to tensorflow-sys/README.md
.
FAQs
Common Issues
One common issue users encounter is compiler errors about missing API parts. Unstable API sections, like the expr
module, are gated by the tensorflow_unstable
feature to prevent accidental use. Users seeking assistance can start by checking the documentation and example folders. Additionally, questions can be posted to the TensorFlow Rust Google Group.
Contributing
The TensorFlow Rust project invites both users and developers to contribute. Participants can join discussions on the TensorFlow Rust Google Group and are encouraged to read the contribution guidelines available in the CONTRIBUTING.md
file. RFCs are labeled with issues tagged as RFCs, inviting community commentary and engagement.
Licensing
This project is distributed under the terms of the Apache 2.0 license, highlighting openness and collaboration. It's important to note that TensorFlow Rust is not an official product of Google.