The best ChatGPT that $100 can buy.
Python
Fix GPU-less CPU use on Linux with specific Torch indexes
Luke Stanley901b07560531
diff --git a/dev/runcpu.sh b/dev/runcpu.shindex e5c7ea8..6290fd9 100644--- a/dev/runcpu.sh+++ b/dev/runcpu.sh@@ -14,7 +14,7 @@ NANOCHAT_BASE_DIR="$HOME/.cache/nanochat"mkdir -p $NANOCHAT_BASE_DIRcommand -v uv &> /dev/null || curl -LsSf https://astral.sh/uv/install.sh | sh[ -d ".venv" ] || uv venv-uv sync+uv sync --extra cpusource .venv/bin/activateif [ -z "$WANDB_RUN" ]; thenWANDB_RUN=dummydiff --git a/pyproject.toml b/pyproject.tomlindex 26625fc..da674f4 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -44,19 +44,35 @@ python_files = ["test_*.py"]python_classes = ["Test*"]python_functions = ["test_*"]-# target torch to cuda 12.8+# target torch to cuda 12.8 or CPU[tool.uv.sources]-torch = [- { index = "pytorch-cpu", marker = "sys_platform != 'linux'" },- { index = "pytorch-cu128", marker = "sys_platform == 'linux'" },+torch = [+ { index = "pytorch-cpu", extra = "cpu" },+ { index = "pytorch-cu128", extra = "gpu" },]-[[tool.uv.index]]-name = "pytorch-cpu"-url = "https://download.pytorch.org/whl/cpu"+[[tool.uv.index]]+name = "pytorch-cpu"+url = "https://download.pytorch.org/whl/cpu"+explicit = true++[[tool.uv.index]]+name = "pytorch-cu128"+url = "https://download.pytorch.org/whl/cu128"explicit = true-[[tool.uv.index]]-name = "pytorch-cu128"-url = "https://download.pytorch.org/whl/cu128"-explicit = true\ No newline at end of file+[project.optional-dependencies]+cpu = [+ "torch>=2.8.0",+]+gpu = [+ "torch>=2.8.0",+]++[tool.uv]+conflicts = [+ [+ { extra = "cpu" },+ { extra = "gpu" },+ ],+]\ No newline at end of filediff --git a/speedrun.sh b/speedrun.shindex d73dcce..35dd39e 100644--- a/speedrun.sh+++ b/speedrun.sh@@ -23,7 +23,7 @@ command -v uv &> /dev/null || curl -LsSf https://astral.sh/uv/install.sh | sh# create a .venv local virtual environment (if it doesn't exist)[ -d ".venv" ] || uv venv# install the repo dependencies-uv sync+uv sync --extra gpu# activate venv so that `python` uses the project's venv instead of system pythonsource .venv/bin/activate