Archived
nemotron 3.5 rerank 8b implementation
This commit is contained in:
1 parent
d773992abc
commit
74e7fddd79
35 files changed
+1788
-90
No files matched your search
@@ -23,3 +23,10 @@ python3 tests/mknemotron35inputgolden.py --tokenizer /path/to/checkpoint/tokeniz
|
||||
The generator needs Jinja2, Hugging Face tokenizers, and the checked-in vision fixture. The
|
||||
golden records the source template, full tokenizer, and subset SHA-256 hashes. It runs no model
|
||||
weights and is never called by CMake or CTest.
|
||||
|
||||
`rerank-template.jinja` is the unchanged template from
|
||||
`nvidia/Nemotron-3.5-Rerank-8B-BF16` revision
|
||||
`f88f8d9104726747791283ab156d2fcdb29e90a7`, under the same retained OpenMDW-1.1
|
||||
license. It supplies the independent query/document rendering oracle to the
|
||||
manually run `tests/mknemotron35rerankgolden.py`; the engine does not execute
|
||||
remote model code. The tiny scoring head is seeded synthetic test data.
|
||||
@@ -0,0 +1,105 @@
|
||||
{%- if messages | length == 2 and messages[0]['role'] == 'query' and messages[1]['role'] == 'document' -%}
|
||||
{# Render the checkpoint's query/document training format without BOS/EOS. #}
|
||||
{%- macro text_content(content) -%}
|
||||
{%- if content is string -%}
|
||||
{{- content | replace('[', '[') | replace('<', '<') -}}
|
||||
{%- else -%}
|
||||
{%- set ns = namespace(first=true) -%}
|
||||
{%- for block in content -%}
|
||||
{%- if block['type'] == 'text' -%}
|
||||
{%- if not ns.first -%}{{- '\n\n' -}}{%- endif -%}
|
||||
{{- block['text'] | replace('[', '[') | replace('<', '<') -}}
|
||||
{%- set ns.first = false -%}
|
||||
{%- elif block['type'] not in ['image', 'image_url'] -%}
|
||||
{{- raise_exception('Only text and image documents are supported') -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{%- if messages | length != 2 or messages[0]['role'] != 'query' or messages[1]['role'] != 'document' -%}
|
||||
{{- raise_exception('Reranking requires a query followed by a document') -}}
|
||||
{%- endif -%}
|
||||
{%- set ns = namespace(images=0) -%}
|
||||
{%- if messages[0]['content'] is not string -%}
|
||||
{%- for block in messages[0]['content'] -%}
|
||||
{%- if block['type'] != 'text' -%}{{- raise_exception('Queries must be text') -}}{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- if messages[1]['content'] is not string -%}
|
||||
{%- for block in messages[1]['content'] -%}
|
||||
{%- if block['type'] in ['image', 'image_url'] -%}{%- set ns.images = ns.images + 1 -%}{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- if ns.images > 1 -%}{{- raise_exception('At most one image per document is supported') -}}{%- endif -%}
|
||||
{%- set rendered -%}
|
||||
{%- if ns.images -%}{{- '[IMG] ' -}}{%- endif -%}
|
||||
{{- 'query: ' -}}{{- text_content(messages[0]['content']) -}}
|
||||
{{- '\n\npassage: ' -}}{{- text_content(messages[1]['content']) -}}
|
||||
{%- endset -%}
|
||||
{{- rendered | trim if ns.images else rendered -}}
|
||||
|
||||
{%- else -%}
|
||||
{# nemo-mistral-retrieval-v1
|
||||
Derived from the Mistral Ministral-3 instruct chat template render_content
|
||||
macro and its image-before-text canonicalization. Retrieval adaptation:
|
||||
system content is the retrieval prefix; generation wrappers and BOS/EOS are
|
||||
deliberately omitted so message inference matches training token for token.
|
||||
#}
|
||||
{%- macro mark_user_text(text) -%}
|
||||
{{- text | replace("[", "[") | replace("<", "<") -}}
|
||||
{%- endmacro -%}
|
||||
{%- macro render_text_content(content, context_name) -%}
|
||||
{%- if content is string -%}
|
||||
{{- content -}}
|
||||
{%- elif content is sequence -%}
|
||||
{%- set ns = namespace(has_output=false) -%}
|
||||
{%- for block in content -%}
|
||||
{%- if block["type"] == "text" -%}
|
||||
{%- if ns.has_output %}{{ "\n\n" }}{% endif -%}
|
||||
{{- block["text"] -}}
|
||||
{%- set ns.has_output = true -%}
|
||||
{%- else -%}
|
||||
{{- raise_exception(context_name + " may contain only text blocks") -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{{- raise_exception(context_name + " must be a string or a list of text blocks") -}}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{%- macro render_user_content(content) -%}
|
||||
{%- if content is string -%}
|
||||
{{- mark_user_text(content) -}}
|
||||
{%- elif content is sequence -%}
|
||||
{%- set ns = namespace(has_output=false) -%}
|
||||
{%- for block in content -%}
|
||||
{%- if block["type"] in ["image", "image_url"] -%}
|
||||
{%- if ns.has_output %}{{ " " }}{% endif -%}
|
||||
{{- "[IMG]" -}}
|
||||
{%- set ns.has_output = true -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- for block in content -%}
|
||||
{%- if block["type"] == "text" -%}
|
||||
{%- if ns.has_output %}{{ " " }}{% endif -%}
|
||||
{{- mark_user_text(block["text"]) -}}
|
||||
{%- set ns.has_output = true -%}
|
||||
{%- elif block["type"] not in ["image", "image_url"] -%}
|
||||
{{- raise_exception("User content supports only text and image blocks") -}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- else -%}
|
||||
{{- raise_exception("User content must be a string or a list of text and image blocks") -}}
|
||||
{%- endif -%}
|
||||
{%- endmacro -%}
|
||||
{%- if messages | length == 1 and messages[0]["role"] == "user" -%}
|
||||
{{- render_user_content(messages[0]["content"]) -}}
|
||||
{%- elif messages | length == 2
|
||||
and messages[0]["role"] == "system"
|
||||
and messages[1]["role"] == "user" -%}
|
||||
{{- render_text_content(messages[0]["content"], "System content") -}}
|
||||
{{- " " -}}
|
||||
{{- render_user_content(messages[1]["content"]) -}}
|
||||
{%- else -%}
|
||||
{{- raise_exception("Retrieval inputs require one user message with an optional leading system prefix") -}}
|
||||
{%- endif -%}
|
||||
{%- endif -%}
|
||||
@@ -0,0 +1 @@
|
||||
{"provenance":{"transformers":"5.20.0","torch":"2.14.1+cpu","seed":3508,"attention":"eager","dtype":"bfloat16","head_arithmetic":"float32","template_revision":"f88f8d9104726747791283ab156d2fcdb29e90a7"},"head":{"shape":[1,16],"bf16":[48599,16068,15923,15757,48680,15518,48674,15855,48551,48633,15760,47978,15920,48837,48538,48654]},"cases":[{"name":"short","inputs":[[3,4,7,12,6]],"offsets":[0],"pooled":[[-0.2314453125,0.25,0.10009765625,0.02734375,1.75,0.63671875,0.232421875,-0.1533203125,0.0247802734375,1.6484375,-0.0027313232421875,0.75390625,-0.5703125,-0.9453125,-1.484375,2.09375]],"scores":[-0.308460533618927],"head_only_scores":[-0.308460533618927]},{"name":"ragged","inputs":[[3,4,7],[12,6,2,8,9]],"offsets":[0,0],"pooled":[[-0.119140625,-0.17578125,0.1396484375,-0.326171875,1.8125,0.435546875,0.0498046875,-0.318359375,-0.26953125,1.6796875,0.004852294921875,0.396484375,-0.2119140625,-1.234375,-1.40625,2.078125],[0.0260009765625,-0.400390625,0.46875,-0.040771484375,0.88671875,0.51171875,0.10400390625,0.228515625,1.046875,1.5,-0.1767578125,0.89453125,0.412109375,-0.35546875,-0.91796875,1.5625]],"scores":[-0.3140508532524109,-0.425670325756073],"head_only_scores":[-0.3140508532524109,-0.425670325756073]},{"name":"q_scale_boundary","inputs":[[3,4,7,12]],"offsets":[16382],"pooled":[[-0.2158203125,0.267578125,0.1533203125,-0.107421875,1.578125,0.71875,0.306640625,-0.1123046875,0.1416015625,1.953125,-0.1630859375,0.48046875,-0.34375,-1.265625,-1.34375,1.8984375]],"scores":[-0.15869462490081787],"head_only_scores":[-0.15869462490081787]}],"multimodal":[{"name":"image_only","inputs":[{"tokens":[10,10,13],"placements":[{"image":1,"tok":0}]}],"pooled":[[-0.78125,-0.099609375,0.55859375,0.306640625,0.51953125,0.58203125,0.2470703125,-2.140625,1.5,-0.435546875,0.1474609375,0.412109375,-2.25,-0.3671875,0.431640625,-1.2578125]],"hidden":[[[-0.76171875,-0.15234375,0.9921875,0.2197265625,0.34375,1.1015625,0.2431640625,-2.09375,1.546875,-0.66015625,-0.026123046875,0.3515625,-2.28125,-0.44140625,0.392578125,-0.96875],[-0.69921875,-0.2392578125,0.98046875,0.3828125,0.390625,0.953125,0.18359375,-2.234375,1.5546875,-0.72265625,0.07568359375,0.25,-2.234375,-0.392578125,0.330078125,-0.84375],[-0.875,0.0927734375,-0.294921875,0.318359375,0.8203125,-0.302734375,0.314453125,-2.109375,1.390625,0.07666015625,0.392578125,0.6328125,-2.21875,-0.26953125,0.578125,-1.96875]]],"scores":[-0.36420053243637085]},{"name":"image_text","inputs":[{"tokens":[3,4,10,10,10,12,10,10,10,13,5,7,8,6],"placements":[{"image":2,"tok":2}]}],"pooled":[[-0.11181640625,0.26171875,0.5859375,0.5078125,1.7890625,1.0546875,0.35546875,-0.79296875,0.94140625,1.1484375,0.349609375,1.109375,-1.3984375,-0.5703125,-0.89453125,1.375]],"hidden":[[[0.17578125,-0.43359375,0.453125,-0.28515625,1.6796875,0.859375,0.34765625,-0.9296875,1.1796875,1.3515625,-0.333984375,0.9375,-1.2734375,-0.61328125,-0.392578125,2.59375],[-0.53125,0.314453125,0.39453125,0.59765625,1.0859375,1.125,0.75390625,-1.296875,1.3046875,0.48046875,0.2041015625,1.015625,-2.03125,-0.77734375,-1.4375,0.9921875],[0.0791015625,0.455078125,0.78515625,0.427734375,1.8671875,1.3984375,0.314453125,-0.71484375,1.15625,1.1796875,0.099609375,1.1875,-1.6953125,-0.486328125,-0.8359375,1.3125],[0.109375,0.46875,0.75,0.439453125,1.796875,1.375,0.314453125,-0.76953125,1.21875,1.1953125,0.24609375,1.1328125,-1.7421875,-0.5078125,-0.8359375,1.296875],[0.11474609375,0.337890625,0.79296875,0.58203125,2.03125,1.1953125,0.29296875,-0.7421875,1.1328125,1.109375,0.1103515625,1.2265625,-1.6484375,-0.375,-0.82421875,1.4453125],[-0.061767578125,0.578125,0.45703125,-0.1796875,1.953125,1.5234375,0.2734375,-0.61328125,1.1953125,1.0859375,0.66796875,0.69140625,-1.40625,-0.9375,-1.3828125,1.09375],[0.048583984375,0.318359375,0.77734375,0.53515625,2.015625,1.265625,0.302734375,-0.7578125,1.1171875,1.171875,0.1708984375,1.1875,-1.6875,-0.41796875,-0.76171875,1.421875],[0.1953125,0.279296875,0.703125,0.578125,1.96875,1.21875,0.27734375,-0.84375,1.140625,1.1640625,0.2275390625,1.171875,-1.6484375,-0.416015625,-0.87109375,1.4453125],[0.10546875,0.384765625,0.8046875,0.53515625,1.859375,1.2890625,0.2392578125,-0.8359375,1.21875,1.15625,0.177734375,1.1015625,-1.609375,-0.498046875,-0.94921875,1.4453125],[-0.1513671875,0.6015625,-0.61328125,0.5703125,2.15625,-0.296875,0.376953125,-0.84375,0.97265625,1.703125,0.53515625,1.3828125,-1.5625,-0.220703125,-0.44921875,0.01153564453125],[0.359375,0.39453125,0.3359375,1.1015625,1.4609375,1.9375,-0.427734375,-0.85546875,0.296875,1.3828125,0.54296875,0.79296875,0.033447265625,-1.1328125,-0.5703125,2.046875],[-0.330078125,-0.1416015625,0.6796875,0.55859375,1.984375,-0.369140625,1.40625,-0.4453125,0.87109375,0.7421875,0.69921875,0.69140625,-1.0703125,-0.41015625,-1.1328125,2.40625],[-0.59375,0.52734375,1.03125,1.421875,1.734375,1.375,0.400390625,-0.8984375,0.32421875,1.2421875,0.341796875,1.2109375,-1.3984375,-0.60546875,-0.90234375,0.21484375],[-1.078125,-0.41015625,0.8359375,0.220703125,1.375,0.84765625,Line truncated
|
||||
Reference in new issue
Block a user