feat(laguna): support Laguna-XS-2.1 via no-default-system-message variant (#97)
This commit is contained in:
@@ -54,6 +54,7 @@ from renderers.configs import (
|
||||
KimiK25RendererConfig,
|
||||
KimiK2RendererConfig,
|
||||
LagunaXS2RendererConfig,
|
||||
LagunaXS21RendererConfig,
|
||||
Llama3RendererConfig,
|
||||
MiniMaxM2RendererConfig,
|
||||
Nemotron3RendererConfig,
|
||||
@@ -139,6 +140,7 @@ __all__ = [
|
||||
"KimiK2RendererConfig",
|
||||
"LagunaXS2Renderer",
|
||||
"LagunaXS2RendererConfig",
|
||||
"LagunaXS21RendererConfig",
|
||||
"Llama3Renderer",
|
||||
"Llama3RendererConfig",
|
||||
"MULTIMODAL_MODELS",
|
||||
|
||||
+4
-1
@@ -1060,8 +1060,10 @@ MODEL_RENDERER_MAP: dict[str, str] = {
|
||||
# construction to pin a different date.
|
||||
"meta-llama/Llama-3.2-1B-Instruct": "llama-3",
|
||||
"meta-llama/Llama-3.2-3B-Instruct": "llama-3",
|
||||
# Poolside Laguna.
|
||||
# Poolside Laguna. XS-2.1's template is byte-identical to XS.2's minus
|
||||
# the default system message; the config name selects the variant.
|
||||
"poolside/Laguna-XS.2": "laguna-xs.2",
|
||||
"poolside/Laguna-XS-2.1": "laguna-xs-2.1",
|
||||
# GPT-OSS.
|
||||
"openai/gpt-oss-20b": "gpt-oss",
|
||||
"openai/gpt-oss-120b": "gpt-oss",
|
||||
@@ -1327,6 +1329,7 @@ def _populate_registry():
|
||||
"kimi-k2": KimiK2Renderer,
|
||||
"kimi-k2.5": KimiK25Renderer,
|
||||
"laguna-xs.2": LagunaXS2Renderer,
|
||||
"laguna-xs-2.1": LagunaXS2Renderer,
|
||||
"llama-3": Llama3Renderer,
|
||||
"nemotron-3": Nemotron3Renderer,
|
||||
"nemotron-3-ultra": Nemotron3UltraRenderer,
|
||||
|
||||
@@ -422,6 +422,27 @@ class LagunaXS2RendererConfig(BaseRendererConfig):
|
||||
chat template's ``render_assistant_messages_raw`` gate."""
|
||||
|
||||
|
||||
class LagunaXS21RendererConfig(BaseRendererConfig):
|
||||
"""Laguna XS-2.1 renderer config — distinct discriminator so auto
|
||||
resolution gives XS-2.1 checkpoints the no-default-system-message
|
||||
template variant.
|
||||
|
||||
XS-2.1's chat template is byte-identical to XS.2's except it ships
|
||||
no default system message: when the caller provides none (and no
|
||||
tools), the ``<system>`` block is omitted entirely. Shares
|
||||
:class:`renderers.laguna_xs2.LagunaXS2Renderer`, which selects the
|
||||
variant from ``config.name``.
|
||||
"""
|
||||
|
||||
name: Literal["laguna-xs-2.1"] = "laguna-xs-2.1"
|
||||
|
||||
enable_thinking: bool = False
|
||||
"""See :class:`LagunaXS2RendererConfig.enable_thinking`."""
|
||||
|
||||
render_assistant_messages_raw: bool = False
|
||||
"""See :class:`LagunaXS2RendererConfig.render_assistant_messages_raw`."""
|
||||
|
||||
|
||||
class Llama3RendererConfig(BaseRendererConfig):
|
||||
"""Llama-3.x Instruct renderer config.
|
||||
|
||||
@@ -576,6 +597,7 @@ RendererConfig = Annotated[
|
||||
KimiK2RendererConfig,
|
||||
KimiK25RendererConfig,
|
||||
LagunaXS2RendererConfig,
|
||||
LagunaXS21RendererConfig,
|
||||
Llama3RendererConfig,
|
||||
MiniMaxM2RendererConfig,
|
||||
Nemotron3RendererConfig,
|
||||
@@ -613,6 +635,7 @@ _CONFIG_BY_NAME: dict[str, type[BaseRendererConfig]] = {
|
||||
"kimi-k2": KimiK2RendererConfig,
|
||||
"kimi-k2.5": KimiK25RendererConfig,
|
||||
"laguna-xs.2": LagunaXS2RendererConfig,
|
||||
"laguna-xs-2.1": LagunaXS21RendererConfig,
|
||||
"llama-3": Llama3RendererConfig,
|
||||
"minimax-m2": MiniMaxM2RendererConfig,
|
||||
"nemotron-3": Nemotron3RendererConfig,
|
||||
@@ -659,6 +682,7 @@ __all__ = [
|
||||
"KimiK25RendererConfig",
|
||||
"KimiK2RendererConfig",
|
||||
"LagunaXS2RendererConfig",
|
||||
"LagunaXS21RendererConfig",
|
||||
"Llama3RendererConfig",
|
||||
"MiniMaxM2RendererConfig",
|
||||
"Nemotron3RendererConfig",
|
||||
|
||||
+26
-17
@@ -1,4 +1,4 @@
|
||||
"""Laguna-XS.2 Renderer.
|
||||
"""Laguna-XS.2 / XS-2.1 Renderer.
|
||||
|
||||
Main properties:
|
||||
- Prefix is the single token ``〈|EOS|〉`` (also the EOS / stop token).
|
||||
@@ -12,10 +12,13 @@ Main properties:
|
||||
- Tool calls: ``<tool_call>`` / ``</tool_call>`` ARE single tokens, but the
|
||||
inner ``<arg_key>`` / ``</arg_key>`` / ``<arg_value>`` / ``</arg_value>``
|
||||
markers are plain text — parsed via regex on the decoded inner block.
|
||||
- The template bakes in a default system prompt when ``messages[0]`` is not
|
||||
a system message. The system block also contains the tools section (under
|
||||
a ``### Tools`` header with an ``<available_tools>`` listing and prose
|
||||
format instructions that vary on ``enable_thinking``).
|
||||
- XS.2's template bakes in a default system prompt when ``messages[0]`` is
|
||||
not a system message; XS-2.1's (otherwise byte-identical) template
|
||||
removed it, so no system message and no tools means no ``<system>``
|
||||
block at all. The config's ``name`` selects the variant. The system
|
||||
block also contains the tools section (under a ``### Tools`` header
|
||||
with an ``<available_tools>`` listing and prose format instructions
|
||||
that vary on ``enable_thinking``).
|
||||
- Reasoning is rendered for every assistant message — no last-user-index
|
||||
gating. ``thinking_retention`` is accepted for protocol uniformity but
|
||||
is effectively a no-op since past reasoning is preserved by default.
|
||||
@@ -39,7 +42,7 @@ from renderers.base import (
|
||||
resolve_thinking_retention,
|
||||
should_rerender_for_thinking_retention,
|
||||
)
|
||||
from renderers.configs import LagunaXS2RendererConfig
|
||||
from renderers.configs import LagunaXS2RendererConfig, LagunaXS21RendererConfig
|
||||
from renderers.parsing import parse_laguna_xs2
|
||||
|
||||
_DEFAULT_SYSTEM_MESSAGE = (
|
||||
@@ -81,7 +84,7 @@ class LagunaXS2Renderer:
|
||||
def __init__(
|
||||
self,
|
||||
tokenizer: PreTrainedTokenizer,
|
||||
config: LagunaXS2RendererConfig | None = None,
|
||||
config: LagunaXS2RendererConfig | LagunaXS21RendererConfig | None = None,
|
||||
):
|
||||
self._tokenizer = tokenizer
|
||||
self.config = config or LagunaXS2RendererConfig()
|
||||
@@ -89,6 +92,11 @@ class LagunaXS2Renderer:
|
||||
self.config,
|
||||
"all",
|
||||
)
|
||||
# XS.2's template bakes in a default system prompt; XS-2.1's
|
||||
# (otherwise byte-identical) template removed it.
|
||||
self._default_system_message = (
|
||||
_DEFAULT_SYSTEM_MESSAGE if self.config.name == "laguna-xs.2" else ""
|
||||
)
|
||||
|
||||
self._eos = self._token_id("〈|EOS|〉")
|
||||
self._think = self._token_id("<think>")
|
||||
@@ -184,7 +192,7 @@ class LagunaXS2Renderer:
|
||||
emit_special(self._eos, -1, is_sampled=False, is_content=False)
|
||||
|
||||
# ── System header (absorbs messages[0] if it's a system message) ──
|
||||
system_content = _DEFAULT_SYSTEM_MESSAGE
|
||||
system_content = self._default_system_message
|
||||
system_msg_idx = -1
|
||||
caller_has_system = bool(messages and messages[0].get("role") == "system")
|
||||
if caller_has_system:
|
||||
@@ -196,16 +204,12 @@ class LagunaXS2Renderer:
|
||||
# gate: when the caller passes an empty system message and no tools,
|
||||
# the whole ``<system>...</system>`` block is omitted.
|
||||
if has_sys_content or tools:
|
||||
# The template emits ``<system>\n`` then conditionally a second
|
||||
# ``\n``. Bundle those into one emit so BPE merges ``\n\n`` into
|
||||
# its single-token form (rather than two ``\n`` atoms).
|
||||
emit_text(
|
||||
"<system>\n\n" if has_sys_content else "<system>\n",
|
||||
-1,
|
||||
is_sampled=False,
|
||||
is_content=False,
|
||||
)
|
||||
if has_sys_content:
|
||||
# The template emits ``<system>\n`` then a second ``\n``
|
||||
# before the system body. Bundle those into one emit so BPE
|
||||
# merges ``\n\n`` into its single-token form (rather than
|
||||
# two ``\n`` atoms).
|
||||
emit_text("<system>\n\n", -1, is_sampled=False, is_content=False)
|
||||
# If the caller provided system content, it's body bytes;
|
||||
# otherwise this is the default system prompt (scaffold).
|
||||
sys_is_content = caller_has_system
|
||||
@@ -224,6 +228,11 @@ class LagunaXS2Renderer:
|
||||
if self.config.enable_thinking
|
||||
else _TOOLS_FOOTER_NO_THINKING
|
||||
)
|
||||
if not has_sys_content:
|
||||
# No system body: ``<system>\n`` runs straight into the
|
||||
# tools header's ``\n\n`` — encode them together so BPE
|
||||
# merges the ``\n\n\n`` seam as the template does.
|
||||
tool_text = "<system>\n" + tool_text
|
||||
emit_text(tool_text, -1, is_sampled=False, is_content=False)
|
||||
emit_text("\n</system>\n", -1, is_sampled=False, is_content=False)
|
||||
|
||||
|
||||
@@ -37,6 +37,9 @@ RENDERER_MODELS = [
|
||||
# name (auto → MODEL_RENDERER_MAP → nemotron-3-ultra).
|
||||
("nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16", "auto"),
|
||||
("poolside/Laguna-XS.2", "auto"),
|
||||
# XS-2.1 resolves to the `laguna-xs-2.1` config variant (no default
|
||||
# system message) via the model name.
|
||||
("poolside/Laguna-XS-2.1", "auto"),
|
||||
# DeepSeek-V3/R1 are intentionally NOT in this shared barrage: their
|
||||
# chat templates can't render the barrage's tool-call fixtures (the
|
||||
# templates require ``tool['type']`` and a string-serialized
|
||||
|
||||
Reference in New Issue
Block a user