Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

chore(setup): add setup_laya.sh and ignore the artifacts it writes

thread3deaee58a1fb1f
diff --git a/.gitignore b/.gitignore
index 3d264b23..15cf1136 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,3 +73,9 @@ site/
# ruff's cache, and the JSON the research harnesses write on every run
.ruff_cache/
research/*_benchmark_results.json
+
+# local setup artifacts written by setup_laya.sh: the checkpoint weights, and the Hugging Face
+# and pip caches it keeps inside the checkout
+models/
+.hf-cache/
+.pip-cache/
diff --git a/setup_laya.sh b/setup_laya.sh
new file mode 100755
index 00000000..8fbe7a42
--- /dev/null
+++ b/setup_laya.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+# Reproducible local setup for Laya on this machine (macOS on Intel x86_64).
+#
+# Creates an isolated virtualenv, installs the only PyTorch release that still ships a
+# macOS Intel wheel, installs the newest transformers that runs on it, downloads the three
+# Laya checkpoints, and verifies the result with a real forward pass.
+#
+# Usage: ./setup_laya.sh [--skip-models] [--skip-verify]
+# Idempotent: re-running only fixes what is missing.
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # repository root
+VENV="$ROOT/.venv"
+PYTHON_BIN="${PYTHON:-python3}"
+
+# Keep every byte this setup writes inside the project directory.
+export PIP_CACHE_DIR="$ROOT/.pip-cache"
+export HF_HOME="$ROOT/.hf-cache"
+export HF_HUB_DISABLE_TELEMETRY=1
+export TOKENIZERS_PARALLELISM=false
+export USE_TF=0 # Laya is torch-only; a stray TensorFlow install can deadlock loading
+export USE_TORCH=1
+
+SKIP_MODELS=0
+SKIP_VERIFY=0
+for arg in "$@"; do
+ case "$arg" in
+ --skip-models) SKIP_MODELS=1 ;;
+ --skip-verify) SKIP_VERIFY=1 ;;
+ *) echo "unknown option: $arg" >&2; exit 2 ;;
+ esac
+done
+
+say() { printf '\n\033[1m==> %s\033[0m\n' "$*"; }
+
+say "Host"
+uname -srm
+"$PYTHON_BIN" -c 'import platform,sys;print("python", sys.version.split()[0], platform.machine())'
+
+if [ "$(uname -s)" != "Darwin" ]; then
+ echo "warning: this script targets macOS; continuing anyway" >&2
+fi
+
+say "Virtualenv at $VENV"
+if [ ! -x "$VENV/bin/python" ]; then
+ "$PYTHON_BIN" -m venv "$VENV"
+fi
+"$VENV/bin/python" -m pip install --quiet --upgrade pip
+
+say "Dependencies"
+# torch: PyPI and download.pytorch.org both stopped publishing macOS x86_64 wheels after
+# 2.2.2, so this is the newest PyTorch this CPU can run from a wheel.
+# numpy: torch 2.2.2 was compiled against NumPy 1.x and fails to initialise under NumPy 2.
+# transformers: 4.57.x is the last 4.x line (5.x requires torch>=2.4, unavailable here) and
+# the oldest line that reads both the ModernBERT and mmBERT checkpoints.
+# huggingface_hub is capped <1.0 by transformers 4.x.
+"$VENV/bin/python" -m pip install \
+ "numpy<2" \
+ "torch==2.2.2" \
+ "transformers==4.57.6" \
+ "safetensors>=0.4.0" \
+ "huggingface_hub>=0.34.0,<1.0"
+
+say "Installing the laya package (editable)"
+"$VENV/bin/python" -m pip install --quiet -e "$ROOT"
+
+if [ "$SKIP_MODELS" -eq 0 ]; then
+ say "Checkpoints -> $ROOT/models"
+ if [ -f "$ROOT/models/laya/model.safetensors" ]; then
+ echo "already present, skipping download"
+ else
+ # One repo bundles all three checkpoints; ~2.3 GB of safetensors.
+ ( cd "$ROOT" && "$VENV/bin/python" - <<'PY'
+from huggingface_hub import snapshot_download
+p = snapshot_download(
+ "convaiinnovations/laya",
+ local_dir="models/laya",
+ allow_patterns=["*.json", "*.safetensors", "*.txt", "tokenizer.json"],
+)
+print("downloaded ->", p)
+PY
+ )
+ fi
+ # tests/test_local_e2e.py expects <root>/{laya,laya-multilingual,laya-typed-decisions};
+ # the bundle ships the two extra checkpoints as subfolders of the first.
+ ln -sfn laya/multilingual "$ROOT/models/laya-multilingual"
+ ln -sfn laya/typed-decisions "$ROOT/models/laya-typed-decisions"
+ ls -l "$ROOT/models"
+fi
+
+# A truncated or silently-updated download turns into quietly wrong answers, so check the weights
+# against the hashes recorded in verify/checkpoints.json. Runs whenever the weights are there,
+# including on a --skip-models re-run.
+if [ -f "$ROOT/models/laya/model.safetensors" ]; then
+ say "Checking checkpoint integrity"
+ "$VENV/bin/python" "$ROOT/verify/checkpoints.py" --models "$ROOT/models"
+elif [ "$SKIP_MODELS" -eq 0 ]; then
+ echo "warning: models/laya/model.safetensors is still missing" >&2
+fi
+
+if [ "$SKIP_VERIFY" -eq 0 ]; then
+ say "Verifying with real weights"
+ "$VENV/bin/python" "$ROOT/laya_smoke_test.py" --models "$ROOT/models"
+fi
+
+say "Done"
+echo "Activate with: source \"$VENV/bin/activate\""
+echo "Run the suite: python tests/test_local_e2e.py \"$ROOT/models\""
diff --git a/tests/test_packaging.py b/tests/test_packaging.py
index 66971a35..f4349a3d 100644
--- a/tests/test_packaging.py
+++ b/tests/test_packaging.py
@@ -117,9 +117,11 @@ def _headings(path):
_md = []
for _dirpath, _dirnames, _filenames in os.walk("."):
- # `.pytest_cache` ships a README of its own and is not part of the repository.
+ # `.pytest_cache` ships a README of its own and is not part of the repository, and `.hf-cache`
+ # holds third-party dataset cards downloaded by setup_laya.sh (both are gitignored).
_dirnames[:] = [d for d in _dirnames
- if d not in (".git", "__pycache__", "node_modules", ".pytest_cache")]
+ if d not in (".git", "__pycache__", "node_modules", ".pytest_cache",
+ ".hf-cache")]
_md.extend(os.path.normpath(os.path.join(_dirpath, f))
for f in _filenames if f.endswith(".md"))
_md = sorted(_md)