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(go): run laya-go/onnx against Python on the real multilingual graph

Adeshina Lasisi4c7a0fbbaa5d
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 2e1574c9..61846951 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -154,6 +154,109 @@ jobs:
${{ runner.temp }}/go-test.json
${{ runner.temp }}/go-test-oldest.json
+ onnx:
+ name: go onnx parity
+ runs-on: ubuntu-latest
+ continue-on-error: true # advisory: see the header
+ timeout-minutes: 75
+ env:
+ ONNX_GRAPH: ${{ github.workspace }}/laya-java/.work/onnx/multilingual/laya.onnx
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
+ with:
+ python-version: "3.12"
+ cache: pip
+ cache-dependency-path: laya-dotnet/tools/requirements-regen.txt
+ - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
+ with:
+ go-version: "1.27.1"
+ cache: false
+ # requirements-regen.txt pins onnxruntime, which also supplies libonnxruntime.so.*: nothing
+ # else is downloaded.
+ - name: Install the Python toolchain the goldens are recorded with
+ run: |
+ python -m pip install --upgrade pip
+ pip install "torch==2.14.0" --index-url https://download.pytorch.org/whl/cpu
+ pip install -r laya-dotnet/tools/requirements-regen.txt
+
+ # The key is byte-identical to the multilingual predict cell in java.yml, so both share one
+ # entry. Like Java's, it is blind to model code outside laya/common.py; the `.laya-revision`
+ # stamp `prepare_checkpoint.py` reads is what stops a stale graph being reused.
+ - name: Cache the exported graph
+ id: graph
+ uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: laya-java/.work/onnx
+ key: laya-java-onnx-${{ runner.os }}-multilingual-${{ hashFiles('laya-java/scripts/prepare_checkpoint.py', 'scripts/export_onnx.py', 'laya/common.py', 'laya-dotnet/tools/requirements-regen.txt') }}
+
+ # HF_TOKEN is scoped to this step, as in java.yml: no other step needs the credential.
+ - name: Prepare the multilingual checkpoint and its graph
+ env:
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
+ CACHE_HIT: ${{ steps.graph.outputs.cache-hit }}
+ run: |
+ if [ "$CACHE_HIT" = "true" ]; then
+ python laya-java/scripts/prepare_checkpoint.py --checkpoint multilingual --no-graph
+ else
+ python laya-java/scripts/prepare_checkpoint.py --checkpoint multilingual
+ fi
+ for f in laya.onnx laya.onnx.data laya.onnx.laya-revision; do
+ test -s "laya-java/.work/onnx/multilingual/$f" || { echo "::error::missing $f"; exit 1; }
+ done
+
+ - name: Regenerate predict.json from Python
+ env:
+ LAYA_FIXTURE_CHECKPOINTS: ${{ github.workspace }}/laya-java/.work/checkpoints
+ LAYA_ONNX_GRAPH: ${{ env.ONNX_GRAPH }}
+ LAYA_PREDICT_MODEL: multilingual
+ PYTHONPATH: ${{ github.workspace }}
+ run: python laya-java/scripts/gen_fixtures.py --strict --out "$GOLDENS" --only predict.json
+
+ - name: Locate the ONNX Runtime library
+ run: |
+ python - <<'PY'
+ import glob, os, sys, onnxruntime
+ found = glob.glob(os.path.join(os.path.dirname(onnxruntime.__file__), "capi", "libonnxruntime.so.*"))
+ if len(found) != 1:
+ sys.exit("expected exactly one libonnxruntime.so.*, found %r" % (found,))
+ with open(os.environ["GITHUB_ENV"], "a") as f:
+ f.write("LAYA_ONNXRUNTIME_LIBRARY=%s\n" % found[0])
+ PY
+
+ - name: Run the onnx tests against the fresh goldens
+ working-directory: laya-go/onnx
+ env:
+ LAYA_GO_FIXTURES: ${{ github.workspace }}/.go-goldens
+ LAYA_CHECKPOINTS: ${{ github.workspace }}/laya-java/.work/checkpoints
+ LAYA_ONNX_GRAPH: ${{ env.ONNX_GRAPH }}
+ run: go test -race -count=1 -json ./... > "$RUNNER_TEMP/go-onnx.json"
+ - name: No onnx test was skipped
+ if: ${{ !cancelled() }}
+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-onnx.json" --min-tests 72
+
+ # go.mod declares go 1.22, so that is what a consumer may build with.
+ - name: Run the onnx tests on the oldest supported Go
+ working-directory: laya-go/onnx
+ env:
+ GOTOOLCHAIN: go1.22.12
+ LAYA_GO_FIXTURES: ${{ github.workspace }}/.go-goldens
+ LAYA_CHECKPOINTS: ${{ github.workspace }}/laya-java/.work/checkpoints
+ LAYA_ONNX_GRAPH: ${{ env.ONNX_GRAPH }}
+ run: go test -count=1 -json ./... > "$RUNNER_TEMP/go-onnx-oldest.json"
+ - name: No onnx test was skipped on the oldest Go either
+ if: ${{ !cancelled() }}
+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-onnx-oldest.json" --min-tests 72
+
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ if: ${{ failure() }}
+ with:
+ name: go-onnx-diagnostics
+ path: |
+ .go-goldens
+ ${{ runner.temp }}/go-onnx.json
+ ${{ runner.temp }}/go-onnx-oldest.json
+
static:
name: go static checks
runs-on: ubuntu-latest
@@ -182,6 +285,19 @@ jobs:
run: |
go install "honnef.co/go/tools/cmd/staticcheck@$STATICCHECK_VERSION"
"$(go env GOPATH)/bin/staticcheck" ./...
+ # The onnx module is nested, so the steps above do not see it. It needs cgo for the real
+ # session and must also build and test without it.
+ - name: onnx go vet
+ working-directory: laya-go/onnx
+ run: go vet ./...
+ - name: onnx staticcheck
+ working-directory: laya-go/onnx
+ run: |
+ go install "honnef.co/go/tools/cmd/staticcheck@$STATICCHECK_VERSION"
+ "$(go env GOPATH)/bin/staticcheck" ./...
+ - name: onnx builds and tests without cgo
+ working-directory: laya-go/onnx
+ run: CGO_ENABLED=0 go build ./... && CGO_ENABLED=0 go test ./...
security:
name: go security scan
@@ -206,3 +322,9 @@ jobs:
run: |
go install "golang.org/x/vuln/cmd/govulncheck@$GOVULNCHECK_VERSION"
"$(go env GOPATH)/bin/govulncheck" ./...
+
+ - name: govulncheck (onnx module)
+ working-directory: laya-go/onnx
+ run: |
+ go install "golang.org/x/vuln/cmd/govulncheck@$GOVULNCHECK_VERSION"
+ "$(go env GOPATH)/bin/govulncheck" ./...
diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml
index 9d48cbac..004ed1d2 100644
--- a/.github/workflows/security.yml
+++ b/.github/workflows/security.yml
@@ -154,8 +154,10 @@ jobs:
# `dotnet build` for it, and a build this change cannot verify locally would turn a
# scanner into a broken required check. laya-dotnet is covered by gitleaks only today;
# adding it needs whoever owns that build to confirm autobuild works. `go` builds the
- # module in laya-go/, not the repo root: autobuild finds laya-go/go.mod itself (checked
- # with the CodeQL CLI: "Found 1 go.mod files in: laya-go/go.mod", 20 non-test files).
+ # modules in laya-go/ and its nested laya-go/onnx/, not the repo root: autobuild finds
+ # both go.mod files itself and builds the onnx module with cgo (checked with the CodeQL
+ # CLI 2.27.1: "Found 2 go.mod files in: laya-go/go.mod, laya-go/onnx/go.mod", and
+ # onnx/session_cgo.go is in the extracted sources), so no explicit build step is needed.
language: [python, java-kotlin, javascript-typescript, go]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1