Skip to content

Commit a296a8a

Browse files
authored
add option to specify computation backend through environment variable (#102)
* add option to specify computation backend through environment variable * update readme
1 parent 44462b6 commit a296a8a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ In fact, `ltt` is `pip` with a few added options:
103103
ltt install --pytorch-computation-backend=cu102 torch
104104
```
105105

106+
Borrowing from the mutex packages that PyTorch provides for `conda` installations,
107+
`--cpuonly` is available as shorthand for `--pytorch-computation-backend=cu102`.
108+
109+
In addition, the computation backend to be installed can also be set through the
110+
`LTT_PYTORCH_COMPUTATION_BACKEND` environment variable. It will only be honored in
111+
case no CLI option for the computation backend is specified.
112+
106113
- By default, `ltt` installs stable PyTorch binaries. To install binaries from the
107114
nightly, test, or LTS channels pass the `--pytorch-channel` option:
108115

light_the_torch/_patch.py

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import functools
55
import itertools
66
import optparse
7+
import os
78
import re
89
import sys
910
import unittest.mock
@@ -145,6 +146,11 @@ def from_pip_argv(cls, argv: List[str]):
145146
}
146147
elif opts.cpuonly:
147148
cbs = {cb.CPUBackend()}
149+
elif "LTT_PYTORCH_COMPUTATION_BACKEND" in os.environ:
150+
cbs = {
151+
cb.ComputationBackend.from_str(string.strip())
152+
for string in os.environ["LTT_PYTORCH_COMPUTATION_BACKEND"].split(",")
153+
}
148154
else:
149155
cbs = cb.detect_compatible_computation_backends()
150156

0 commit comments

Comments
 (0)