Skip to content

Commit c83c668

Browse files
justinchubyCopilot
andauthored
Fix ONNX GenAI special-token authority (#644)
## Summary - emit execution-relevant numeric token IDs once under `package.tokenizer.special_tokens` - preserve ordered multi-EOS package defaults while making workflow EOS tensors runtime-bound request overrides - remove authored `package.eos_ids` and `package.eos_token_ids` literals from decoder and VLM workflows - cover image, video, audio, and vision-start placeholders; restrict CTC metadata to relevant blank/padding semantics - stamp schema v1.2 independently of tokenizer availability and retain public `SpecialTokenFact` compatibility - refresh decoder, static-cache, and VLM conformance fixtures ## Contract Token IDs are package facts. Token spellings, added-token mappings, and chat templates remain authoritative in tokenizer assets. Termination policy consumes resolved package defaults or an explicit request replacement but owns no duplicate IDs. Consumer schema/runtime: justinchuby/onnx-genai#2171 (**merged** as `e599dc0f067d35aa5326ce5c97d83d2fd6d02f78`) Reader guide: justinchuby/onnx-genai#2143 Baseline coverage repair: #647 ## Validation - **1,095 passed / 250 skipped** across `src/mobius/integrations/onnx_genai` and `tests/model_coverage_test.py` - full `lintrunner` - generated schema and fixture validation - `git diff --check` - architecture and benchmark checks report no graph or performance regression - merged consumer validation passes **28/28 hosted repositories and 56/56 metadata files** This branch is temporarily stacked on #647 solely to avoid known current-`main` coverage failures. After #647 merges, rebase this PR onto current `main` so only the two producer commits remain, rerun the focused gates, and merge. --------- Signed-off-by: justinchuby <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 2e08e9b commit c83c668

10 files changed

Lines changed: 400 additions & 277 deletions

File tree

‎src/mobius/integrations/onnx_genai/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
PackageFacts,
7272
SpecialTokenFact,
7373
SpecialTokenRole,
74+
TokenFacts,
7475
TokenizerArtifact,
7576
TokenizerFacts,
7677
build_tokenizer_facts,
@@ -119,6 +120,7 @@
119120
"SchedulerConfig",
120121
"SpecialTokenFact",
121122
"SpecialTokenRole",
123+
"TokenFacts",
122124
"TokenizerArtifact",
123125
"TokenizerFacts",
124126
"add_policy_components_to_workflow",

‎src/mobius/integrations/onnx_genai/_schema/inference_metadata.schema.json‎

Lines changed: 112 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@
22342234
"type": "null"
22352235
}
22362236
],
2237-
"description": "Exact tokenizer, vocabulary, and special-token facts."
2237+
"description": "Exact tokenizer and vocabulary facts."
22382238
}
22392239
},
22402240
"type": "object"
@@ -2621,7 +2621,12 @@
26212621
},
26222622
{
26232623
"const": "eos_token_ids",
2624-
"description": "Token ids that end generation.\n\nA set, not a single id: a model may end a turn with one token and a\nmessage with another, and both must stop. Declaring it here is what lets\nthe runtime's stop policy read a package's EOS from the package instead\nof rediscovering it from tokenizer side-files it may not ship.",
2624+
"description": "Token ids that end generation.\n\nThe request value overrides\n`package.tokenizer.special_tokens.eos_token_id`. It never carries an\nauthored package default.",
2625+
"type": "string"
2626+
},
2627+
{
2628+
"const": "eos_token_lengths",
2629+
"description": "Number of valid entries in each row of a padded EOS-id tensor.",
26252630
"type": "string"
26262631
},
26272632
{
@@ -2976,28 +2981,6 @@
29762981
},
29772982
"type": "object"
29782983
},
2979-
"SpecialTokenFact": {
2980-
"additionalProperties": false,
2981-
"description": "One special token, pinned by id and exact surface bytes.",
2982-
"properties": {
2983-
"content": {
2984-
"description": "Exact UTF-8 surface form of the token.",
2985-
"minLength": 1,
2986-
"type": "string"
2987-
},
2988-
"id": {
2989-
"description": "Vocabulary id of the token.",
2990-
"format": "uint32",
2991-
"minimum": 0,
2992-
"type": "integer"
2993-
}
2994-
},
2995-
"required": [
2996-
"id",
2997-
"content"
2998-
],
2999-
"type": "object"
3000-
},
30012984
"SpeculationSafety": {
30022985
"description": "Whether an effect may be executed inside a speculative region.",
30032986
"oneOf": [
@@ -3993,6 +3976,94 @@
39933976
],
39943977
"type": "object"
39953978
},
3979+
"TokenFacts": {
3980+
"additionalProperties": false,
3981+
"description": "Numeric model and control-token facts.\n\nThese ids are model/package facts. Token spellings, added-token maps, and\nchat templates remain in tokenizer assets and are not repeated here.",
3982+
"properties": {
3983+
"audio_token_id": {
3984+
"description": "Prompt placeholder replaced by audio features.",
3985+
"format": "uint32",
3986+
"minimum": 0,
3987+
"type": [
3988+
"integer",
3989+
"null"
3990+
]
3991+
},
3992+
"bos_token_id": {
3993+
"description": "Beginning-of-sequence token.",
3994+
"format": "uint32",
3995+
"minimum": 0,
3996+
"type": [
3997+
"integer",
3998+
"null"
3999+
]
4000+
},
4001+
"decoder_start_token_id": {
4002+
"description": "First token fed to an encoder-decoder's autoregressive decoder.",
4003+
"format": "uint32",
4004+
"minimum": 0,
4005+
"type": [
4006+
"integer",
4007+
"null"
4008+
]
4009+
},
4010+
"eos_token_id": {
4011+
"description": "Every token id that terminates package-default autoregressive generation.",
4012+
"items": {
4013+
"format": "uint32",
4014+
"minimum": 0,
4015+
"type": "integer"
4016+
},
4017+
"type": "array"
4018+
},
4019+
"image_token_id": {
4020+
"description": "Prompt placeholder replaced by image features.",
4021+
"format": "uint32",
4022+
"minimum": 0,
4023+
"type": [
4024+
"integer",
4025+
"null"
4026+
]
4027+
},
4028+
"pad_token_id": {
4029+
"description": "Padding token used by package-authored tensor contracts.",
4030+
"format": "uint32",
4031+
"minimum": 0,
4032+
"type": [
4033+
"integer",
4034+
"null"
4035+
]
4036+
},
4037+
"sep_token_id": {
4038+
"description": "Separator token used by sequence-pair models.",
4039+
"format": "uint32",
4040+
"minimum": 0,
4041+
"type": [
4042+
"integer",
4043+
"null"
4044+
]
4045+
},
4046+
"video_token_id": {
4047+
"description": "Prompt placeholder replaced by video features.",
4048+
"format": "uint32",
4049+
"minimum": 0,
4050+
"type": [
4051+
"integer",
4052+
"null"
4053+
]
4054+
},
4055+
"vision_start_token_id": {
4056+
"description": "Token that opens a vision segment in a multimodal prompt.",
4057+
"format": "uint32",
4058+
"minimum": 0,
4059+
"type": [
4060+
"integer",
4061+
"null"
4062+
]
4063+
}
4064+
},
4065+
"type": "object"
4066+
},
39964067
"TokenizerArtifact": {
39974068
"additionalProperties": false,
39984069
"description": "One package-relative tokenizer artifact.",
@@ -4015,7 +4086,10 @@
40154086
"algorithm": {
40164087
"description": "Tokenizer algorithm identifier, e.g. `bpe`, `unigram`, `wordpiece`.",
40174088
"minLength": 1,
4018-
"type": "string"
4089+
"type": [
4090+
"string",
4091+
"null"
4092+
]
40194093
},
40204094
"artifacts": {
40214095
"description": "Package-relative tokenizer artifacts.",
@@ -4031,23 +4105,26 @@
40314105
"type": "boolean"
40324106
},
40334107
"special_tokens": {
4034-
"additionalProperties": {
4035-
"$ref": "#/$defs/SpecialTokenFact"
4036-
},
4037-
"description": "Special tokens by semantic role, e.g. `bos`, `eos`, `pad`.",
4038-
"type": "object"
4108+
"anyOf": [
4109+
{
4110+
"$ref": "#/$defs/TokenFacts"
4111+
},
4112+
{
4113+
"type": "null"
4114+
}
4115+
],
4116+
"description": "Numeric model and control-token facts for this tokenizer vocabulary.\n\nToken strings, added-token mappings, and chat templates remain in the\ntokenizer assets. Request EOS inputs may override these defaults, but\nworkflow literals and termination components do not own another copy."
40394117
},
40404118
"vocab_size": {
40414119
"description": "Number of entries in the vocabulary, including added tokens.",
40424120
"format": "uint",
40434121
"minimum": 1,
4044-
"type": "integer"
4122+
"type": [
4123+
"integer",
4124+
"null"
4125+
]
40454126
}
40464127
},
4047-
"required": [
4048-
"algorithm",
4049-
"vocab_size"
4050-
],
40514128
"type": "object"
40524129
},
40534130
"VisionOutputBinding": {

‎src/mobius/integrations/onnx_genai/auto_export_test.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ def test_dispatch_decoder(tmp_path):
244244
}
245245
assert application_inputs == {
246246
"request.prompt_lengths",
247-
"request.eos_ids",
248-
"request.eos_lengths",
249247
"request.row_max_iterations",
250248
"request.rng_counter",
251249
}
250+
assert workflow["inputs"]["request.eos_ids"]["role"]["role"] == "eos_token_ids"
251+
assert workflow["inputs"]["request.eos_lengths"]["role"]["role"] == "eos_token_lengths"
252252
assert workflow["inputs"]["request.prompt_lengths"]["default"] == -1
253253
assert [node["component"] for node in workflow["steps"][0]["setup"]] == [
254254
"decoder_state_initializer",

0 commit comments

Comments
 (0)