Skip to content

Studio: Inkling support fixes - #7153

Merged
danielhanchen merged 2 commits into
mainfrom
studio-inkling-support
Jul 15, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-inkling-support

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes accumulated while bringing TML Inkling up in Studio on multi-GPU B200s.

Backend

  • Context compute-buffer sizing for Inkling. The banded-attention path reserves a small compute buffer (~8 KiB per context token at ub=512), but a quantized KV cache forces the dense relative-bias fallback whose reserve is ~402 KiB per token. Size the context fit for the active KV cache type so a q8_0 cache gets a small honest context instead of an unloadable one that crash-loops the server.
  • Tool-call healing for typed content-block markers. Inkling emits tool calls as <|content_invoke_tool_json|>{...} blocks, optionally preceded by a bare tool-name echo. Teach tool healing, the strict parser, and passthrough healing to recognize the marker, accept the args key alias, and trim the name echo so narration-then-call turns never leak raw JSON into chat.
  • Download worker HF token fallback. The hub download worker scrubs inherited HF env vars and only injects the Studio settings token. When no settings token is configured, fall back to the backend's own HF_TOKEN so private repos resolve instead of failing with 401.
  • Numeric reasoning-effort mapping. Inkling's chat template takes a numeric thinking-effort dial (0 to 0.99) and coerces unknown named levels to 0, silently disabling thinking. Map OpenAI-style names to the trained values (none 0, low 0.2, medium 0.7, high 0.9, xhigh/max 0.99) at launch and per request.

Frontend

  • Audio attachments get an audio icon and an "Audio" type label instead of the generic file tile.
  • Reasoning-effort picker now works for pure reasoning_effort templates and surfaces the template's none level when there is no dedicated off toggle.

Tests

  • Extended the passthrough-healing and strict-parser suites for the new marker; healing/tool batteries pass (422 tests) plus the server-args suite (226).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the Inkling model architecture, including handling its custom reasoning effort levels, estimating its compute buffer requirements, and parsing its native tool call format (<|content_invoke_tool_json|>). It also adds audio attachment detection in the frontend to display appropriate icons and labels. The review feedback suggests retrieving the Hugging Face token via huggingface_hub.get_token() to support cached local logins, using safe dictionary access in llama_cpp.py to prevent a potential KeyError, and ensuring consistent contentType extraction for audio attachments in the frontend.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +80 to 82
if not hf_token:
hf_token = os.environ.get("HF_TOKEN") or None
env["HF_HUB_DISABLE_IMPLICIT_TOKEN"] = "0" if hf_token else "1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When retrieving the Hugging Face token, retrieve it using huggingface_hub.get_token() instead of only checking os.environ.get('HF_TOKEN'). This ensures cached local logins are also supported. Additionally, ensure the token is explicitly set in the env dictionary.

Suggested change
if not hf_token:
hf_token = os.environ.get("HF_TOKEN") or None
env["HF_HUB_DISABLE_IMPLICIT_TOKEN"] = "0" if hf_token else "1"
if not hf_token:
import huggingface_hub
hf_token = huggingface_hub.get_token() or os.environ.get("HF_TOKEN")
if hf_token:
env["HF_TOKEN"] = hf_token
env["HF_HUB_DISABLE_IMPLICIT_TOKEN"] = "0" if hf_token else "1"
References
  1. When verifying or scanning gated or private Hugging Face models, retrieve the Hugging Face token using huggingface_hub.get_token() instead of only checking os.environ.get('HF_TOKEN') to support cached local logins.

Comment on lines +771 to +774
logger.info(
f"{prefix}model supports reasoning "
f"(reasoning_effort: {flags['reasoning_effort_levels'] or 'default levels'})"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the scanned template does not contain both 'low' and 'high', the key 'reasoning_effort_levels' is not added to the flags dictionary. Accessing flags['reasoning_effort_levels'] directly in the logging statement will then raise a KeyError. Use flags.get('reasoning_effort_levels') to safely handle this case.

Suggested change
logger.info(
f"{prefix}model supports reasoning "
f"(reasoning_effort: {flags['reasoning_effort_levels'] or 'default levels'})"
)
logger.info(
f"{prefix}model supports reasoning "
f"(reasoning_effort: {flags.get('reasoning_effort_levels') or 'default levels'})"
)

Comment on lines +173 to +178
return isAudioAttachment(
attachment.name,
(attachment as { file?: File }).file?.type ?? "",
)
? "Audio"
: "File";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In AttachmentUI, the extraction of contentType only checks (attachment as { file?: File }).file?.type and misses (attachment as { contentType?: string }).contentType. This is inconsistent with AttachmentThumb (lines 131-136) and will fail to identify audio attachments that only have a top-level contentType property (e.g., when loaded from history without a local File object). Extract the content type consistently.

        const contentType =
          (attachment as { file?: File }).file?.type ??
          (attachment as { contentType?: string }).contentType ??
          "";
        return isAudioAttachment(attachment.name, contentType) ? "Audio" : "File";

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0986589089

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"<|tool_calls_section_begin|>",
"<|tool_call_begin|>",
# TML Inkling native call marker.
"<|content_invoke_tool_json|>",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip Inkling tool markup after parsing it

When Inkling emits a text tool call such as <|message_model|>web_search<|content_invoke_tool_json|>{...}<|end_message|>, this new signal now makes the GGUF loop parse and execute the call, but strip_tool_markup(..., final=True) still has no pattern for this marker. The loop uses that stripped value as content_text before appending the assistant tool-call message, so the raw marker/JSON remains in conversation history (and can leak back into chat) after a successfully executed Inkling tool call.

Useful? React with 👍 / 👎.

kwargs["enable_thinking"] = enable_thinking
if self._supports_preserve_thinking and preserve_thinking is not None:
kwargs["preserve_thinking"] = preserve_thinking
self._coerce_reasoning_effort(kwargs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept xhigh/max before coercing Inkling effort

For pure reasoning_effort models, the frontend can now advertise and send xhigh/max levels, and _coerce_reasoning_effort has mappings for them, but this branch only puts none|low|medium|high (plus minimal as low) into kwargs before the coercion call. An Inkling request with reasoning_effort: "max" or "xhigh" and no enable_thinking therefore returns no chat_template_kwargs, so the selected top effort is silently ignored instead of being mapped to 0.99.

Useful? React with 👍 / 👎.

const clampedReasoningEffort =
reasoningStyle === "enable_thinking_effort"
reasoningStyle === "enable_thinking_effort" ||
reasoningStyle === "reasoning_effort"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Surface None in the shared composer too

This path now preserves backend-advertised levels for pure reasoning_effort models, including Inkling's "none" effort, but the shared/Compare composer still does .filter((level) => level !== "none") when rendering its Think menu. Loading the same Inkling model through that composer therefore exposes the richer levels in state while still giving the user no way to pick effort 0/None there, unlike the regular thread composer updated in this commit.

Useful? React with 👍 / 👎.

# [n_kv, ub, n_head] f32 (~402 KiB per context token at ub=512); size the
# fit for that so a q8_0 cache gets a small honest context instead of an
# unloadable one that crash-loops the server.
if cache_type_kv and _kv_bytes_per_elem(cache_type_kv) < 2.0:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for inherited quantized Inkling caches

This check only charges the dense Inkling fallback when the collapsed cache_type_kv argument is a quantized type, but Studio intentionally leaves inherited quantized LLAMA_ARG_CACHE_TYPE_K/V env settings as None for budgeting and can also collapse asymmetric extras to the heavier f16 axis. In those supported configurations the child still runs with a quantized KV cache, but this branch takes the 8 KiB/token banded estimate instead of the ~402 KiB/token dense reserve, so auto-fit can again select an unloadable context and crash-loop.

Useful? React with 👍 / 👎.

"[TOOL_CALLS]",
# TML Inkling native call marker (leaks as text when the server-side
# parser misses a narration-then-call turn).
"<|content_invoke_tool_json|>",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the Inkling name echo in the stream buffer

In streaming passthrough, _earliest_signal now starts holding at <|content_invoke_tool_json|> and immediately emits everything before it as text. For Inkling's documented <|message_model|>NAME<|content_invoke_tool_json|>{...} shape, that means the bare role/name echo is already sent to the client before tool_healing can fold it into the promoted span, so streaming healed turns leak visible <|message_model|>lookup/lookup text ahead of the structured tool call.

Useful? React with 👍 / 👎.

"<|tool_calls_section_begin|>",
"<|tool_call_begin|>",
# TML Inkling native call marker.
"<|content_invoke_tool_json|>",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat Inkling blocks as outer tool envelopes

Adding the Inkling marker to the shared signal list makes the parser wake up for these blocks, but _marker_inside_leading_envelope still does not recognize <|content_invoke_tool_json|> as the outer call. If an Inkling argument string contains a literal DeepSeek/Kimi marker (for example a search query about <|tool_call_begin|>web_search:0...), the pre-pass parses that inner text first and returns the wrong tool call instead of the surrounding Inkling JSON.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit 85b49ee into main Jul 15, 2026
3 of 50 checks passed
@danielhanchen
danielhanchen deleted the studio-inkling-support branch July 15, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant