doc: improve doc for burn-tch (#2288)

* doc: improve doc for burn-tch

* improve doc about config.toml

* improve doc about config.toml
This commit is contained in:
王翼翔 2024-09-23 19:52:10 +08:00 committed by GitHub
parent 20ab5e31d7
commit 13ad4d285d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 1 deletions

View File

@ -243,11 +243,14 @@ is to use a PyTorch installation. This requires a Python installation.
_Note: MPS acceleration is available on MacOS 12.3+._ _Note: MPS acceleration is available on MacOS 12.3+._
```shell ```shell
pip install torch==2.2.0 pip install torch==2.2.0 numpy==1.26.4 setuptools
export LIBTORCH_USE_PYTORCH=1 export LIBTORCH_USE_PYTORCH=1
export DYLD_LIBRARY_PATH=/path/to/pytorch/lib:$DYLD_LIBRARY_PATH export DYLD_LIBRARY_PATH=/path/to/pytorch/lib:$DYLD_LIBRARY_PATH
``` ```
**Note:** if `venv` is used, it should be activated during coding and building,
or the compiler may not work properly.
## Example Usage ## Example Usage
For a simple example, check out any of the test programs in [`src/bin/`](./src/bin/). Each program For a simple example, check out any of the test programs in [`src/bin/`](./src/bin/). Each program
@ -255,3 +258,27 @@ sets the device to use and performs a simple element-wise addition.
For a more complete example using the `tch` backend, take a loot at the For a more complete example using the `tch` backend, take a loot at the
[Burn mnist example](https://github.com/tracel-ai/burn/tree/main/examples/mnist). [Burn mnist example](https://github.com/tracel-ai/burn/tree/main/examples/mnist).
## Too many environment variables?
Try `.cargo/config.toml` ([cargo book](https://doc.rust-lang.org/cargo/reference/config.html#env)).
Instead of setting the environments in your shell, you can manually add them to your `.cargo/config.toml`:
```toml
[env]
LD_LIBRARY_PATH = "/absolute/path/to/libtorch/lib"
LIBTORCH = "/absolute/path/to/libtorch/libtorch"
```
Or use bash commands below:
```bash
mkdir .cargo
cat <<EOF > .cargo/config.toml
[env]
LD_LIBRARY_PATH = "/absolute/path/to/libtorch/lib:$LD_LIBRARY_PATH"
LIBTORCH = "/absolute/path/to/libtorch/libtorch"
EOF
```
This will automatically include the old `LD_LIBRARY_PATH` value in the new one.