From f5fb774b83088f24480ff08952df0d2a9989f0b0 Mon Sep 17 00:00:00 2001 From: elkoled Date: Wed, 16 Sep 2026 14:47:06 -0700 Subject: [PATCH 1/5] Repair virtualenv ownership before setup --- setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.sh b/setup.sh index 4e91e46..6366553 100755 --- a/setup.sh +++ b/setup.sh @@ -8,6 +8,11 @@ mkdir -p .cache as_root=() if [ "$EUID" -ne 0 ]; then as_root=(sudo); fi +for directory in .cache .venv models frames; do + if [ -d "$directory" ] && [ -n "$(find "$directory" ! -user "$(id -un)" -print -quit)" ]; then + "${as_root[@]}" chown -R "$(id -u):$(id -g)" "$directory" + fi +done download() { curl --retry 5 --retry-delay 5 --retry-all-errors -fLsS "$1" -o "$2"; } case "$(uname -s):$(uname -m)" in From 5252feddeea85f414b229bd728fa7c74bf65ab71 Mon Sep 17 00:00:00 2001 From: elkoled Date: Wed, 16 Sep 2026 15:31:49 -0700 Subject: [PATCH 2/5] Show setup model progress --- setup.sh | 2 ++ tools/export.py | 1 + 2 files changed, 3 insertions(+) diff --git a/setup.sh b/setup.sh index 6366553..fc09bd6 100755 --- a/setup.sh +++ b/setup.sh @@ -84,7 +84,9 @@ if ! command -v uv >/dev/null; then download https://astral.sh/uv/install.sh .cache/install-uv.sh UV_NO_MODIFY_PATH=1 sh .cache/install-uv.sh fi +unset VIRTUAL_ENV uv sync --locked --python 3.12 .venv/bin/python tools/setup.py +echo 'Preparing models...' .venv/bin/python tools/export.py echo 'Ready. Activate with: source .venv/bin/activate' diff --git a/tools/export.py b/tools/export.py index 68a902a..0f76b24 100644 --- a/tools/export.py +++ b/tools/export.py @@ -13,3 +13,4 @@ model = resnet18(weights=ResNet18_Weights.DEFAULT).eval() torch.onnx.export(model, torch.zeros(1, 3, 224, 224), folder / 'resnet18.onnx', input_names=['image'], output_names=['scores'], opset_version=17, dynamo=False) +print('Models ready.', flush=True) From 193fb52f9ea19e339240b758e7176188babb8aca Mon Sep 17 00:00:00 2001 From: elkoled Date: Wed, 16 Sep 2026 15:36:27 -0700 Subject: [PATCH 3/5] Keep model downloads in the project cache --- setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.sh b/setup.sh index fc09bd6..8ee2de0 100755 --- a/setup.sh +++ b/setup.sh @@ -3,6 +3,7 @@ set -euo pipefail cd "$(dirname "$0")" export PATH="$HOME/.local/bin:/opt/homebrew/bin:$PATH" export UV_CACHE_DIR="${UV_CACHE_DIR:-$PWD/.cache/uv}" +export TORCH_HOME="${TORCH_HOME:-$PWD/.cache/torch}" export UV_HTTP_TIMEOUT=200 UV_HTTP_RETRIES=5 mkdir -p .cache From 9f3a70e48a5a4d1d01148faa66162c5da1c4726b Mon Sep 17 00:00:00 2001 From: elkoled Date: Wed, 16 Sep 2026 15:37:54 -0700 Subject: [PATCH 4/5] Keep all model caches in the repository --- examples/01_chat.py | 2 +- examples/04_classify.py | 2 +- examples/vision.py | 2 +- setup.sh | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/01_chat.py b/examples/01_chat.py index 7de11cf..4438dd0 100644 --- a/examples/01_chat.py +++ b/examples/01_chat.py @@ -3,7 +3,7 @@ from pathlib import Path os.environ.setdefault("DEV", "CPU") -os.environ.setdefault("XDG_CACHE_HOME", str(Path(__file__).resolve().parents[1] / ".cache")) +os.environ["XDG_CACHE_HOME"] = str(Path(__file__).resolve().parents[1] / ".cache") from tinygrad.llm.cli import main if __name__ == "__main__": diff --git a/examples/04_classify.py b/examples/04_classify.py index 2aed187..e1070dc 100644 --- a/examples/04_classify.py +++ b/examples/04_classify.py @@ -4,7 +4,7 @@ ROOT = Path(__file__).resolve().parents[1] os.environ.setdefault('DEV', 'CPU') -os.environ.setdefault('XDG_CACHE_HOME', str(ROOT / '.cache')) +os.environ['XDG_CACHE_HOME'] = str(ROOT / '.cache') from PIL import Image from torchvision.models import ResNet18_Weights diff --git a/examples/vision.py b/examples/vision.py index 2c1a36d..7c25bd4 100644 --- a/examples/vision.py +++ b/examples/vision.py @@ -2,7 +2,7 @@ from pathlib import Path os.environ.setdefault("DEV", "CPU") -os.environ.setdefault("XDG_CACHE_HOME", str(Path(__file__).resolve().parents[1] / ".cache")) +os.environ["XDG_CACHE_HOME"] = str(Path(__file__).resolve().parents[1] / ".cache") import numpy as np import torch diff --git a/setup.sh b/setup.sh index 8ee2de0..321ff70 100755 --- a/setup.sh +++ b/setup.sh @@ -2,8 +2,9 @@ set -euo pipefail cd "$(dirname "$0")" export PATH="$HOME/.local/bin:/opt/homebrew/bin:$PATH" -export UV_CACHE_DIR="${UV_CACHE_DIR:-$PWD/.cache/uv}" -export TORCH_HOME="${TORCH_HOME:-$PWD/.cache/torch}" +export XDG_CACHE_HOME="$PWD/.cache" +export UV_CACHE_DIR="$XDG_CACHE_HOME/uv" +export TORCH_HOME="$XDG_CACHE_HOME/torch" export UV_HTTP_TIMEOUT=200 UV_HTTP_RETRIES=5 mkdir -p .cache From 016c190164ffa98ea7ff19c9f5ffa01802367d39 Mon Sep 17 00:00:00 2001 From: elkoled Date: Wed, 16 Sep 2026 15:39:38 -0700 Subject: [PATCH 5/5] Scope setup cache variables --- setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 321ff70..23d27ed 100755 --- a/setup.sh +++ b/setup.sh @@ -2,9 +2,8 @@ set -euo pipefail cd "$(dirname "$0")" export PATH="$HOME/.local/bin:/opt/homebrew/bin:$PATH" -export XDG_CACHE_HOME="$PWD/.cache" -export UV_CACHE_DIR="$XDG_CACHE_HOME/uv" -export TORCH_HOME="$XDG_CACHE_HOME/torch" +export UV_CACHE_DIR="$PWD/.cache/uv" +export TORCH_HOME="$PWD/.cache/torch" export UV_HTTP_TIMEOUT=200 UV_HTTP_RETRIES=5 mkdir -p .cache