Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

mlx: clip long laya states instead of rejecting them

Jeffrey Morgan80cedab04432
diff --git a/mlxrunner/model/laya/score.go b/mlxrunner/model/laya/score.go
index 67b464a05..5b2c8f3f2 100644
--- a/mlxrunner/model/laya/score.go
+++ b/mlxrunner/model/laya/score.go
@@ -74,11 +74,10 @@ func (m *Model) sequence(state string, q llm.ScoreQuestion, maxLen int) (ids, ma
if len(ids)+1 > maxLen {
return nil, nil, 0, fmt.Errorf("decision question requires %d tokens; context limit is %d", len(ids)+1, maxLen)
}
+ // Like the publisher's build_sequence, keep the start of a state that
+ // doesn't fit.
stateTokens := m.tok.Encode(state, false)
- if limit := maxLen - len(ids) - 1; len(stateTokens) > limit {
- return nil, nil, 0, fmt.Errorf("state has %d tokens; limit is %d with this question", len(stateTokens), limit)
- }
- ids = append(ids, stateTokens...)
+ ids = append(ids, stateTokens[:min(len(stateTokens), maxLen-len(ids)-1)]...)
ids = append(ids, m.sep)
return ids, markers, qtype, nil
}
diff --git a/mlxrunner/model/laya/score_test.go b/mlxrunner/model/laya/score_test.go
index 5a9815e08..6ca409234 100644
--- a/mlxrunner/model/laya/score_test.go
+++ b/mlxrunner/model/laya/score_test.go
@@ -31,7 +31,7 @@ func TestPrepareScoreInputLimits(t *testing.T) {
wantError string
}{
{"context boundary", strings.Repeat("x", 36), "x", []string{"x", "x"}, 64, 64, ""},
- {"state overflow", strings.Repeat("x", 37), "x", []string{"x", "x"}, 64, 0, "state has 37 tokens; limit is 36"},
+ {"state clipped to the context", strings.Repeat("x", 37), "x", []string{"x", "x"}, 64, 64, ""},
{"question overflow", "", "x", []string{"x", "x"}, 27, 0, "decision question requires 28 tokens; context limit is 27"},
{"option boundary", "x", "x", []string{strings.Repeat("x", 47), "x"}, 512, 75, ""},
{"option overflow", "x", "x", []string{strings.Repeat("x", 48), "x"}, 512, 0, "option 0 has 49 tokens; limit is 48"},