cpu-mode-assertions-torch
Assert CPU-only runtime inside a container using PyTorch (torch.cuda.is_available()==False) and optional env var checks. Use to prevent accidental GPU execution during CPU smoke tests.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Skill Instructions
Inputs
-
SERVICE_CONTAINER(string): container name to exec into -
CPU_DEVICE_ENV(string, optional): env var to validate (e.g.ASR_DEVICE) -
CPU_DEVICE_EXPECTED(string, optional): expected value (e.g.cpu)
Procedure
set -euo pipefail
service_container="${SERVICE_CONTAINER:?SERVICE_CONTAINER is required}"
# 1) Env assertion (optional)
if [ -n "${CPU_DEVICE_ENV:-}" ]; then
docker exec "$service_container" printenv "$CPU_DEVICE_ENV"
fi
# 2) Runtime assertion (torch)
docker exec "$service_container" python - <<'PY'
import torch
print('torch_version=', torch.__version__)
print('torch_cuda_is_available=', torch.cuda.is_available())
print('torch_cuda_version=', getattr(torch.version, 'cuda', None))
PY
Acceptance Criteria
-
torch_cuda_is_availableprintsFalse - If
CPU_DEVICE_ENVis provided, its value equalsCPU_DEVICE_EXPECTED(orcpuif you standardize it)
Why
Prevents “silent GPU path” during CPU smoke testing (different behavior, heavier images, device-specific bugs).
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-26
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!