Skip to content

Commit 13f1b15

Browse files
committed
Auto-hide cuda device option when no GPU is present
1 parent f78933f commit 13f1b15

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

app/streamlit_app.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,23 @@
135135
if problem_kind == "hopfield":
136136
extra["patterns"] = st.slider("Stored patterns P", 1, 20, 3)
137137

138-
device = st.selectbox("Device", ("cpu", "cuda"), index=0)
138+
# Only offer devices that are actually available on the host. On public
139+
# deployments (Streamlit Cloud / Hugging Face Spaces) this is always
140+
# ``cpu``; on a local workstation with a GPU the ``cuda`` option appears.
141+
import torch # noqa: PLC0415 - lazy import to keep startup snappy
142+
143+
device_options = ["cpu"]
144+
if torch.cuda.is_available():
145+
device_options.append("cuda")
146+
device = st.selectbox(
147+
"Device",
148+
device_options,
149+
index=0,
150+
help=(
151+
"The annealing loop runs inside this Streamlit process. "
152+
"`cuda` appears only when a GPU is visible to PyTorch."
153+
),
154+
)
139155

140156

141157
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)