Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0b14f5e
chore(dotnet): scaffold .NET SDK solution and projects
kevin-gatimu Sep 28, 2026
d045396
feat(dotnet): add Python-compatible JSON dialects
kevin-gatimu Sep 28, 2026
12cd932
feat(dotnet): add HuggingFace tokenizer binding
kevin-gatimu Sep 28, 2026
2081276
feat(dotnet): add options, model config and artifact resolution with …
kevin-gatimu Sep 28, 2026
1fa53c3
feat(dotnet): add typed questions, sequence builder and collator
kevin-gatimu Sep 28, 2026
edef7fd
feat(dotnet): add calibration and typed answers
kevin-gatimu Sep 28, 2026
2d969b9
feat(dotnet): add ONNX inference engine and presets
kevin-gatimu Sep 28, 2026
5277d30
test(dotnet): add golden-vector parity suite against the Python SDK
kevin-gatimu Sep 28, 2026
8de1e1a
feat(dotnet): add language detection
kevin-gatimu Sep 28, 2026
cbad9f9
feat(dotnet): add email cleaning
kevin-gatimu Sep 28, 2026
99e0478
feat(dotnet): add embedding shortlist for high-cardinality choice
kevin-gatimu Sep 28, 2026
1854b2e
feat(dotnet): add checkpoint router
kevin-gatimu Sep 28, 2026
290e101
docs(dotnet): add quickstart sample
kevin-gatimu Sep 28, 2026
dfcbf67
docs(dotnet): add routing sample
kevin-gatimu Sep 28, 2026
9f5c6bd
perf(dotnet): add benchmark sample with Python baseline
kevin-gatimu Sep 28, 2026
6a2e022
docs(dotnet): add SDK README
kevin-gatimu Sep 28, 2026
8ccaf96
ci(dotnet): regenerate goldens from Python and run parity tests on ev…
kevin-gatimu Oct 2, 2026
3638a07
fix(dotnet): match current Python language detection rules
kevin-gatimu Oct 2, 2026
f3a4fce
fix(dotnet): match Python default and mixed-language route reasons
kevin-gatimu Oct 2, 2026
be14e6b
fix(dotnet): preserve email requests and match current client markers
kevin-gatimu Oct 2, 2026
6c6cca7
fix(dotnet): report surviving options and actual sequence budget
kevin-gatimu Oct 2, 2026
2d7a307
fix(dotnet): return rendered criterion text in score legends
kevin-gatimu Oct 2, 2026
4f22e90
test(dotnet): regenerate goldens from Python 0.3.24
kevin-gatimu Oct 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
name: .NET

# Parity lane for laya-dotnet. The golden fixtures under laya-dotnet/tests/Laya.Tests/golden are
# recorded from the Python `laya` package, so this runs on EVERY push and pull request (no path
# filter): a change to laya/ that moves what the goldens capture must show up here as a red
# check, not as silent drift. Each run re-records the goldens from the Python code at that commit
# (tools/regen_golden.py) and runs the C# tests against the fresh copies.

on:
pull_request:
push:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: dotnet-${{ github.event_name == 'pull_request' && github.ref || github.sha }}
# Cancel outdated pull request runs. Pushes get a per-commit group so each one finishes.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

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"
DOTNET_NOLOGO: "true"
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
GOLDEN: laya-dotnet/tests/Laya.Tests/golden

jobs:
build:
name: build + model-free tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
cache: pip
cache-dependency-path: laya-dotnet/tools/requirements-regen.txt
- name: Install
run: |
python -m pip install --upgrade pip
# CPU-only torch; the routing goldens only import laya, they never run a model
pip install "torch==2.14.0" --index-url https://download.pytorch.org/whl/cpu
pip install -r laya-dotnet/tools/requirements-regen.txt
- name: Test regeneration cache and skip guard
run: python laya-dotnet/tools/test_ci_tools.py
- name: Regenerate the routing goldens from Python
run: python laya-dotnet/tools/regen_golden.py --checkpoint routing
- name: Golden drift vs. committed (informational)
run: |
git --no-pager diff --stat -- "$GOLDEN"
git status --short -- "$GOLDEN"
- uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: laya-dotnet/global.json
- name: Build (library, samples and tests, warnings are errors)
working-directory: laya-dotnet
run: dotnet build Laya.slnx -c Release
- name: Tests that need no model
working-directory: laya-dotnet
run: >
dotnet test --solution Laya.slnx -c Release --no-build
--results-directory "$RUNNER_TEMP/trx" --report-xunit-trx --report-xunit-trx-filename build.trx
--filter-not-class Laya.Tests.PredictParityTests
--filter-not-class Laya.Tests.ShapeSweepTests
--filter-not-class Laya.Tests.TokenizerParityTests
--filter-not-class Laya.Tests.RouterEndToEndTests
--filter-not-class Laya.Tests.ShortlistEndToEndTests
# With the model-backed classes filtered out nothing may be skipped, so every checkpoint
# is listed as expected to run.
- name: No test was skipped
if: ${{ !cancelled() }}
run: >
python laya-dotnet/tools/check_test_skips.py "$RUNNER_TEMP/trx/build.trx"
--have english multilingual typed-decisions --min-passed 600
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: dotnet-build-diagnostics
path: |
${{ runner.temp }}/trx
${{ env.GOLDEN }}/routing

parity:
name: parity (${{ matrix.name }})
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- name: english
checkpoints: english
filter: --filter-class Laya.Tests.PredictParityTests Laya.Tests.TokenizerParityTests Laya.Tests.ShapeSweepTests Laya.Tests.ShortlistEndToEndTests
min-passed: 50
- name: multilingual
checkpoints: multilingual
filter: --filter-class Laya.Tests.PredictParityTests Laya.Tests.TokenizerParityTests Laya.Tests.ShapeSweepTests Laya.Tests.ShortlistEndToEndTests
min-passed: 50
- name: typed-decisions
checkpoints: typed-decisions
filter: --filter-class Laya.Tests.PredictParityTests Laya.Tests.TokenizerParityTests Laya.Tests.ShapeSweepTests Laya.Tests.ShortlistEndToEndTests
min-passed: 50
# The router end-to-end tests load english and multilingual side by side.
- name: router
checkpoints: english multilingual
filter: --filter-class Laya.Tests.RouterEndToEndTests
min-passed: 1
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "3.12"
cache: pip
cache-dependency-path: laya-dotnet/tools/requirements-regen.txt
- name: Install
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 exports are the slow part (download, trace, verify). They depend only on the pinned
# Hugging Face revision (HF_REVISION in regen_golden.py), the two exporters, the pinned
# toolchain and the model definition in laya/common.py, so that is the cache key; the
# script re-checks the same inputs itself before it reuses a directory. The goldens are
# never cached: they are always re-recorded.
- name: Cache pinned Hugging Face downloads
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/huggingface/hub
key: laya-hf-${{ runner.os }}-${{ matrix.name }}-${{ hashFiles('laya-dotnet/tools/regen_golden.py', 'laya-dotnet/tools/export_onnx.py', 'laya-ts/scripts/export_onnx.py') }}
- name: Cache exported english artifacts
if: ${{ contains(matrix.checkpoints, 'english') }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
onnx/english
onnx-split/english
key: laya-onnx-${{ runner.os }}-english-${{ hashFiles('laya-dotnet/tools/regen_golden.py', 'laya-dotnet/tools/export_onnx.py', 'laya-ts/scripts/export_onnx.py', 'laya-dotnet/tools/requirements-regen.txt', 'laya/common.py') }}
- name: Cache exported multilingual artifacts
if: ${{ contains(matrix.checkpoints, 'multilingual') }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
onnx/multilingual
onnx-split/multilingual
key: laya-onnx-${{ runner.os }}-multilingual-${{ hashFiles('laya-dotnet/tools/regen_golden.py', 'laya-dotnet/tools/export_onnx.py', 'laya-ts/scripts/export_onnx.py', 'laya-dotnet/tools/requirements-regen.txt', 'laya/common.py') }}
- name: Cache exported typed-decisions artifacts
if: ${{ contains(matrix.checkpoints, 'typed-decisions') }}
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
onnx/typed-decisions
onnx-split/typed-decisions
key: laya-onnx-${{ runner.os }}-typed-decisions-${{ hashFiles('laya-dotnet/tools/regen_golden.py', 'laya-dotnet/tools/export_onnx.py', 'laya-ts/scripts/export_onnx.py', 'laya-dotnet/tools/requirements-regen.txt', 'laya/common.py') }}

- name: Export the checkpoints and regenerate their goldens from Python
run: |
args=()
for c in ${{ matrix.checkpoints }}; do args+=(--checkpoint "$c"); done
python laya-dotnet/tools/regen_golden.py "${args[@]}"
# Informational only: float noise across platforms is expected, the C# tests and their
# tolerances are the gate.
- name: Golden drift vs. committed (informational)
run: |
git --no-pager diff --stat -- "$GOLDEN"
git status --short -- "$GOLDEN"

- uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
global-json-file: laya-dotnet/global.json
# The fused layout is found through LAYA_ONNX_ROOT; the split layout through the test
# project's walk-up to <repo>/onnx-split, which is where the script wrote it.
- name: Run the tests against the fresh goldens
working-directory: laya-dotnet
env:
LAYA_ONNX_ROOT: ${{ github.workspace }}/onnx
LAYA_TEST_CHECKPOINTS: ${{ matrix.checkpoints }}
run: >
dotnet test --solution Laya.slnx -c Release
--results-directory "$RUNNER_TEMP/trx" --report-xunit-trx --report-xunit-trx-filename parity.trx
${{ matrix.filter }}
# Missing artifacts make the model-backed tests skip, and a skip is not a failure to
# `dotnet test`. Fail the run unless every skip is for a checkpoint this job does not own.
- name: No model-backed test was skipped
if: ${{ !cancelled() }}
run: >
python laya-dotnet/tools/check_test_skips.py "$RUNNER_TEMP/trx/parity.trx"
--have ${{ matrix.checkpoints }} --min-passed ${{ matrix.min-passed }}
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
if: ${{ failure() }}
with:
name: dotnet-parity-diagnostics-${{ matrix.name }}
path: |
${{ runner.temp }}/trx
${{ env.GOLDEN }}
37 changes: 37 additions & 0 deletions laya-dotnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Build output
[Bb]in/
[Oo]bj/
[Oo]ut/
artifacts/

# Test results and coverage
TestResults/
*.trx
coverage*.json
coverage*.xml
*.coverage

# BenchmarkDotNet
BenchmarkDotNet.Artifacts/

# NuGet
*.nupkg
*.snupkg
.nuget/

# IDE / user state
.vs/
.vscode/
.idea/
*.user
*.suo
*.rsuser
*.DotSettings.user

# Downloaded model artifacts
*.onnx
*.onnx_data

# Python tool caches (tools/)
__pycache__/
*.pyc
42 changes: 42 additions & 0 deletions laya-dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Changelog

All notable changes to the `Laya.Onnx` NuGet package are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
[Semantic Versioning](https://semver.org/). Releases are tagged `laya-dotnet-v<version>`.

## [0.1.0] - unreleased

First release: a port of the Laya Python SDK, tested against laya (Python) 0.3.24.

### Added

- `LayaEngine`: `choice`, `score` and `noul` predictions over the exported ONNX checkpoints
(english, multilingual, typed-decisions); all questions for a state run in one batched forward pass.
- Loads both ONNX layouts: the fused `model.onnx` and the split `encoder.onnx` + `head.onnx`.
- Answers report `confidence` and `answer_confidence` (added in Python 0.3.21).
- Python-compatible sequence building, JSON serialization and calibration, checked against goldens
recorded from the Python SDK.
- Checkpoint router, language detection, email state and option shortlisting.
- Opt-in model download from Hugging Face.
- Samples: quickstart, routing and benchmark.

### Fixed

- Undetermined Latin text uses the router's configured default, including its route reason.
- Language detection counts unlisted scripts, distinguishes mixed-language fields and lines
(`MixedSegment`), and applies current script, stopword and loanword rules.
- Email cleaning preserves unpunctuated requests before disclaimers, distinguishes prose from
signatures and reply headers, and handles Portuguese, Spanish and French client markers.
- Oversized questions report the surviving option markers and the actual sequence budget.
- Score legends return the same rendered criterion text shown to the model, including JSON for
structured levels.
- Golden fixtures regenerated from current Python for all three checkpoints and routing.

### Known gaps

- Python-only opt-in features are not yet ported: abstention (`min_confidence`), `predict_long`,
`lang_temperatures`, hooks, batching APIs, question option ordering and digest controls.
- `LayaEmail.State` does not expose Python's `max_chars` keyword; use `CleanBody` with a custom
budget and pass the cleaned body with `clean: false`.
- New Python usage diagnostics (`state_tokens`, `truncated`, `state_tokens_dropped` and
`truncated_questions`) are not exposed by the .NET `Usage` record.
10 changes: 10 additions & 0 deletions laya-dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions laya-dotnet/Laya.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Solution>
<Folder Name="/samples/">
<Project Path="samples/Laya.Benchmark/Laya.Benchmark.csproj" />
<Project Path="samples/Laya.Routing/Laya.Routing.csproj" />
<Project Path="samples/Laya.Sample/Laya.Sample.csproj" />
</Folder>
<Folder Name="/src/">
<Project Path="src/Laya/Laya.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/Laya.Tests/Laya.Tests.csproj" />
</Folder>
</Solution>
Loading