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.

fix(dotnet): keep two checkpoints loaded by default, as Python does

kevin-gatimuaf043b5a4a68
diff --git a/laya-dotnet/CHANGELOG.md b/laya-dotnet/CHANGELOG.md
index a3a0ebd0..8e539e3a 100644
--- a/laya-dotnet/CHANGELOG.md
+++ b/laya-dotnet/CHANGELOG.md
@@ -26,6 +26,8 @@ goldens: 0.4.0).
### Fixed
+- `LayaRouterOptions.MaxLoaded` defaults to 2, as Python's `Router(max_loaded=2)` does, so a
+ router that alternates two languages no longer reloads a checkpoint on every request.
- 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.
diff --git a/laya-dotnet/src/Laya/LayaRouter.cs b/laya-dotnet/src/Laya/LayaRouter.cs
index 942bbf0a..d8e93a60 100644
--- a/laya-dotnet/src/Laya/LayaRouter.cs
+++ b/laya-dotnet/src/Laya/LayaRouter.cs
@@ -34,11 +34,12 @@ public sealed class LayaRouterOptions
public LayaOptions EngineOptions { get; set; } = new();
/// <summary>
- /// How many checkpoints stay resident at once (least-recently-used is evicted). Default 1,
- /// matching Python. Raised automatically by <see cref="LayaRouter.Attach"/> and
+ /// How many checkpoints stay resident at once (least-recently-used is evicted). Default 2,
+ /// matching Python's <c>Router(max_loaded=2)</c>, so alternating two languages does not reload
+ /// a checkpoint on every request. Raised automatically by <see cref="LayaRouter.Attach"/> and
/// <see cref="LayaRouter.Preload"/> to fit what they load.
/// </summary>
- public int MaxLoaded { get; set; } = 1;
+ public int MaxLoaded { get; set; } = 2;
/// <summary>
/// Checkpoint used when a state has no letters or its Latin language is undetermined without
diff --git a/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs b/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs
index 6fe2f8c0..086b9dc4 100644
--- a/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs
+++ b/laya-dotnet/tests/Laya.Tests/LayaRouterTests.cs
@@ -198,6 +198,19 @@ public sealed class LayaRouterTests
Assert.Equal([LayaCheckpoint.Multilingual], router.Loaded);
}
+ [Fact]
+ public void DefaultKeepsTwoCheckpointsLikePython()
+ {
+ // Python's Router(max_loaded=2) since #180: alternating two languages must not reload.
+ Assert.Equal(2, new LayaRouterOptions().MaxLoaded);
+ using var router = NewFakeRouter(new LayaRouterOptions());
+ router.Load("english");
+ router.Load("multilingual");
+ Assert.Equal(2, router.Loaded.Count);
+ Assert.Contains(LayaCheckpoint.English, router.Loaded);
+ Assert.Contains(LayaCheckpoint.Multilingual, router.Loaded);
+ }
+
[Fact]
public void Cap2EvictsOldest()
{