Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

TPU bug fixes

HenryNdubuakub297f001ede4
diff --git a/pyproject.toml b/pyproject.toml
index 73a02c0..aba3ce6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -12,6 +12,10 @@ dependencies = [
"wandb",
]
+[project.optional-dependencies]
+tpu = ["jax[tpu]"]
+gpu = ["jax[cuda12]"]
+
[project.scripts]
needle = "src.cli:main"
diff --git a/setup b/setup
index 527aaa7..1c580c4 100755
--- a/setup
+++ b/setup
@@ -53,8 +53,8 @@ echo "Installing dependencies..."
pip install --upgrade pip -q
pip install -e . -q
-# If running on a TPU VM, load drivers and install JAX with TPU support
-if lspci 2>/dev/null | grep -qi "google.*processing"; then
+# Detect accelerator and install the matching JAX variant
+if lspci 2>/dev/null | grep -qi "\[ff00\].*google\|google.*processing"; then
echo "TPU hardware detected..."
# Load kernel modules if not already loaded
@@ -79,6 +79,18 @@ if lspci 2>/dev/null | grep -qi "google.*processing"; then
echo "Enabling transparent hugepages..."
sudo sh -c "echo always > /sys/kernel/mm/transparent_hugepage/enabled" 2>/dev/null || true
fi
+
+elif command -v nvidia-smi &>/dev/null && nvidia-smi &>/dev/null; then
+ echo "NVIDIA GPU detected..."
+ GPU_COUNT=$(nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | wc -l)
+ echo "GPU devices: $GPU_COUNT"
+ nvidia-smi --query-gpu=name --format=csv,noheader 2>/dev/null | head -4
+
+ echo "Installing jax[cuda12]..."
+ pip install "jax[cuda12]" -q
+
+else
+ echo "No accelerator detected, using CPU-only JAX."
fi
if [ -z "$WANDB_API_KEY" ]; then
diff --git a/src/train.py b/src/train.py
index e479255..0623c44 100644
--- a/src/train.py
+++ b/src/train.py
@@ -225,7 +225,10 @@ def train(args):
os.makedirs(args.checkpoint_dir, exist_ok=True)
global_step = 0
- causal_mask = make_causal_mask(args.max_dec_len)
+ causal_mask = jnp.broadcast_to(
+ make_causal_mask(args.max_dec_len),
+ (num_devices, 1, args.max_dec_len, args.max_dec_len),
+ )
adam_schedule = optax.warmup_cosine_decay_schedule(
init_value=0.0, peak_value=args.lr,
diff --git a/test.py b/test.py
deleted file mode 100644
index c8640d9..0000000
--- a/test.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import jax
-import jax.numpy as jnp
-
-print(f"JAX version: {jax.__version__}")
-print(f"Number of devices: {jax.device_count()}")
-print(f"Available devices: {jax.devices()}")
-
-# Run a simple calculation
-x = jnp.ones((2, 2))
-y = jnp.dot(x, x)
-print(f"Calculation result: {y}")