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.

ci: add tests, lint, security scanning and a tag-driven release

Nandakishorbe8ce9206649
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..43dfb209
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,16 @@
+version: 2
+updates:
+ - package-ecosystem: pip
+ directory: "/"
+ schedule:
+ interval: weekly
+ open-pull-requests-limit: 5
+ labels: [dependencies]
+
+ # Actions are the other half of the supply chain: a compromised action runs with the
+ # workflow's token. Keep them current, and prefer pinning to a SHA for third-party ones.
+ - package-ecosystem: github-actions
+ directory: "/"
+ schedule:
+ interval: weekly
+ labels: [dependencies, ci]
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 00000000..65fdbefa
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,82 @@
+name: CI
+
+on:
+ pull_request:
+ push:
+ branches: [main]
+
+concurrency:
+ group: ci-${{ github.ref }}
+ cancel-in-progress: true
+
+env:
+ # transformers probes for TensorFlow at import; when TF is present its abseil runtime can
+ # deadlock model construction. Laya is torch-only.
+ USE_TF: "0"
+ USE_TORCH: "1"
+ TOKENIZERS_PARALLELISM: "false"
+
+jobs:
+ test:
+ name: tests (py${{ matrix.python }})
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ python: ["3.9", "3.11", "3.13"]
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: ${{ matrix.python }}
+ cache: pip
+
+ - name: Install
+ run: |
+ python -m pip install --upgrade pip
+ # CPU-only torch keeps the job under a minute instead of pulling CUDA wheels
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
+ pip install -e .
+
+ - name: Import check
+ run: python -c "import laya; print(laya.__version__); print(sorted(laya.__all__))"
+
+ - name: Routing and language-detection tests
+ run: python tests/test_router.py
+
+ lint:
+ name: lint
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+ - run: pip install ruff
+ - name: Ruff
+ run: ruff check laya/ --select=E9,F63,F7,F82,F401,F811 --line-length=120
+ - name: Byte-compile every module
+ run: python -m compileall -q laya/ tests/
+
+ build:
+ name: package
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+ - run: pip install build twine
+ - run: python -m build
+ - name: Validate metadata
+ run: python -m twine check dist/*
+ - name: Version must match the tag on a release
+ if: startsWith(github.ref, 'refs/tags/v')
+ run: |
+ pkg=$(python -c "import re;print(re.search(r'version = \"(.*)\"', open('pyproject.toml').read()).group(1))")
+ tag="${GITHUB_REF_NAME#v}"
+ test "$pkg" = "$tag" || { echo "pyproject $pkg != tag $tag"; exit 1; }
+ - uses: actions/upload-artifact@v4
+ with:
+ name: dist
+ path: dist/
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 00000000..01cbb868
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,90 @@
+name: Release
+
+# Tag a commit v0.2.1 and push it; this builds, verifies the version matches the tag,
+# publishes to PyPI and opens a GitHub Release.
+#
+# Set up once: PyPI -> Publishing -> add a Trusted Publisher for
+# owner NandhaKishorM, repo laya, workflow release.yml, environment pypi
+# Then no API token ever lives in GitHub secrets.
+
+on:
+ push:
+ tags: ["v*"]
+ workflow_dispatch:
+
+permissions:
+ contents: write # create the GitHub Release
+ id-token: write # PyPI trusted publishing
+
+env:
+ USE_TF: "0"
+ USE_TORCH: "1"
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+
+ - name: Install
+ run: |
+ python -m pip install --upgrade pip build twine
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
+ pip install -e .
+
+ - name: Tests must pass before anything is published
+ run: python tests/test_router.py
+
+ - name: Build
+ run: python -m build
+
+ - name: Version matches the tag
+ run: |
+ pkg=$(python -c "import re;print(re.search(r'version = \"(.*)\"', open('pyproject.toml').read()).group(1))")
+ tag="${GITHUB_REF_NAME#v}"
+ echo "pyproject=$pkg tag=$tag"
+ test "$pkg" = "$tag" || { echo "::error::pyproject version $pkg does not match tag $tag"; exit 1; }
+
+ - run: python -m twine check dist/*
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: dist
+ path: dist/
+
+ pypi:
+ needs: build
+ runs-on: ubuntu-latest
+ environment: pypi
+ permissions:
+ id-token: write
+ steps:
+ - uses: actions/download-artifact@v4
+ with:
+ name: dist
+ path: dist/
+ - uses: pypa/gh-action-pypi-publish@release/v1
+
+ github_release:
+ needs: build
+ runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ - uses: actions/download-artifact@v4
+ with:
+ name: dist
+ path: dist/
+ - name: Publish release
+ env:
+ GH_TOKEN: ${{ github.token }}
+ run: |
+ gh release create "$GITHUB_REF_NAME" dist/* \
+ --title "$GITHUB_REF_NAME" \
+ --generate-notes
diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml
new file mode 100644
index 00000000..656c9380
--- /dev/null
+++ b/.github/workflows/security.yml
@@ -0,0 +1,78 @@
+name: Security
+
+on:
+ pull_request:
+ push:
+ branches: [main]
+ schedule:
+ - cron: "17 6 * * 1" # Monday morning: catch CVEs disclosed since the last push
+
+# Read-only by default. Jobs that need more ask for it explicitly.
+permissions: read-all
+
+jobs:
+ secrets:
+ name: secret scan
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0 # gitleaks needs history to scan every commit in the PR
+ - name: gitleaks
+ uses: gitleaks/gitleaks-action@v2
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+
+ deps:
+ name: dependency CVEs
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.11"
+ - run: pip install pip-audit
+ - name: pip-audit
+ run: |
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
+ pip install -e .
+ pip-audit --strict --desc
+
+ codeql:
+ name: CodeQL
+ runs-on: ubuntu-latest
+ permissions:
+ security-events: write
+ actions: read
+ contents: read
+ steps:
+ - uses: actions/checkout@v4
+ - uses: github/codeql-action/init@v3
+ with:
+ languages: python
+ queries: security-extended
+ - uses: github/codeql-action/analyze@v3
+
+ supply_chain:
+ name: no unsafe deserialization
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - name: Weights must load through safetensors, never pickle
+ run: |
+ # torch.load / pickle execute arbitrary code during deserialization. Laya loads
+ # checkpoints from the Hub, so a pickle path would be remote code execution on
+ # `laya.load("someone/their-model")`.
+ if grep -rnE "\bpickle\b|torch\.load\(|joblib\.load\(|yaml\.load\(" laya/; then
+ echo "::error::unsafe deserialization in the shipped package - use safetensors"
+ exit 1
+ fi
+ echo "OK: no pickle/torch.load/yaml.load in laya/"
+ - name: No shell-out or dynamic exec in the shipped package
+ run: |
+ if grep -rnE "os\.system\(|subprocess\.|shell=True|\beval\(|\bexec\(" laya/ \
+ | grep -v "\.eval()"; then
+ echo "::error::shell-out or dynamic execution in the shipped package"
+ exit 1
+ fi
+ echo "OK: no os.system/subprocess/eval/exec in laya/"
diff --git a/laya/agent.py b/laya/agent.py
index 1058bbd5..ff81c8ea 100644
--- a/laya/agent.py
+++ b/laya/agent.py
@@ -1,7 +1,7 @@
"""High-level inference runtime for laya System 1 decision models."""
import json
import os
-from typing import Any, Dict, List, Optional, Union
+from typing import Any, Dict, Optional, Union
import numpy as np
import torch
diff --git a/laya/lang.py b/laya/lang.py
index 82ada195..cf26b3e9 100644
--- a/laya/lang.py
+++ b/laya/lang.py
@@ -11,7 +11,6 @@ Script detection is exact. The Latin-script language guess is a stopword/diacrit
is explicitly best-effort: pass an explicit model or `lang=` when you already know the language.
"""
import re
-import unicodedata
from typing import Dict, List, Optional, Union
# Unicode blocks that the English (ModernBERT-large, 50k English BPE) checkpoint cannot read.
diff --git a/tests/test_router.py b/tests/test_router.py
index 01e32634..388c9cb4 100644
--- a/tests/test_router.py
+++ b/tests/test_router.py
@@ -58,6 +58,21 @@ for label, text, want in [
check("is_english/" + label, is_english(text), want)
+# --------------------------------------------------------------------- Latin language guess
+for label, text, want in [
+ ("english", "The customer was charged twice and wants a refund for this invoice", "en"),
+ ("french", "Le client a ete facture deux fois et il demande un remboursement pour la facture", "fr"),
+ ("german", "Der Kunde wurde zweimal belastet und moechte eine Rueckerstattung fuer die Rechnung", "de"),
+ ("spanish", "El cliente fue cobrado dos veces y quiere que le devuelvan el dinero por la factura", "es"),
+ ("too short", "refund", None),
+]:
+ check("latin_lang/" + label, guess_latin_language(text), want)
+# a non-English guess must never fire on ordinary English
+check("latin_lang/long english stays en",
+ guess_latin_language("Please refund the duplicate charge on invoice 4411 today because "
+ "we have been waiting for three days and nobody has replied to us"), "en")
+
+
# --------------------------------------------------------------------- state flattening
check("state_text/dict", "charged twice" in state_text({"body": "charged twice", "n": 3}), True)
check("state_text/nested", "deep" in state_text({"a": {"b": ["deep"]}}), True)