Skip to content

Studio: keep the SYSTEM prompt of an Ollama model made from a Modelfile - #18045

Merged
Lyxot merged 6 commits into
unslothai:mainfrom
NilayYadav:ollama-model-modelfile-system-prompt
Nov 17, 2026
Merged

Lyxot merged 6 commits into
unslothai:mainfrom
NilayYadav:ollama-model-modelfile-system-prompt

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

A model built with ollama create from a Modelfile that has a SYSTEM line shows up in the chat picker under Ollama, but chatting with it in Studio ignores that SYSTEM text. The model answers as the bare base model, with nothing to say the prompt was dropped. This hits personas and fine-tunes exported with the system message they were trained on.

When the loaded model is an Ollama model with a SYSTEM layer and the chat has no system prompt of its own, that text is now sent as the system prompt, the way Ollama does it. A system prompt set in Studio, or sent by an API client, still replaces it, and the current date line still goes in front of it when that setting is on.

Screenshots

Before (main)

After (this PR)

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T05:19:04.066621Z da3c514 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 36d767351a

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: e78e0030a8

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: e78e0030a8

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 17, 2026
@Lyxot Lyxot self-assigned this Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
…red since #18036) (#18072)

## Summary

`Repo tests (CPU, rest-2)` fails on main since #18036 (seen on #18045,
on `0d4793e1`):

```
tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding
AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding, ...
  'tests/_ddp_trainable_embeddings_worker.py:81: open()'
```

#18036 added `tests/_ddp_trainable_embeddings_worker.py`, which writes
each rank's result JSON with `open(path, "w")`, so it uses the platform
default encoding (cp1252 on Windows). The repo-wide guard requires every
`open()` in the test trees to name an encoding.

The DDP change itself is fine; only the new helper missed the
convention. The guard is doing its job.

## Change

- `tests/_ddp_trainable_embeddings_worker.py`: the result file is
written with `encoding = "utf-8"`.
- `tests/test_ddp_find_unused_default.py`: the two `read_text()` calls
that read those files back pass `encoding = "utf-8"` too, so the writer
and the reader agree on every platform.

## Verification

- `tests/test_source_read_encoding.py -k checked_in_file_reads`: fails
on main with the line above, passes with this change.
@Lyxot

Lyxot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Pushed da3c514 on top of the branch (fast-forward; main is 16 ahead with no conflicts, so I didn't merge it).

The Modelfile SYSTEM fallback now also reaches two routes that still dropped it:

  • /chat/count_tokens: the chat context meter now counts the Modelfile SYSTEM, using the same rule as generation.
  • Anthropic /v1/messages and /v1/messages/count_tokens: these fall back when the translated request has no system text. That matches Ollama, where an absent or empty system (including empty text blocks) gets the Modelfile SYSTEM.

Verified live with a real ollama create model (Qwen3.5-0.8B GGUF, two tags sharing the weights with different SYSTEM text):

  • On main, every route answers as the base model.
  • With this branch, chat, tools, Responses and Anthropic all follow the persona.
  • A request system prompt still wins, and an empty chat system turn suppresses the persona, as Ollama does.
  • Switching between the two tags picks the right persona.

Tests are in studio/backend/tests/test_ollama_modelfile_system_prompt.py (7 pass).

@Lyxot

Lyxot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: da3c51462e

ℹ️ 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".

@Lyxot

Lyxot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Wrap-up for da3c514:

  • Codex: Didn't find any major issues on da3c514 (Studio: keep the SYSTEM prompt of an Ollama model made from a Modelfile #18045 (comment)). I replied to and resolved both earlier Codex threads (context-meter count, Anthropic /v1/messages); da3c514 fixes both.
  • CI: the upstream checks were still all queued after about an hour, so CI ran on a staging copy with the same head and base a462bc160c: [staging] unslothai/unsloth#18045: keep the SYSTEM prompt of an Ollama model made from a Modelfile Lyxot/unsloth#249 (now closed). Result: 55 passed, 6 failed, 4 skipped. None of the 6 failures comes from this PR:
    • Studio test_image_generate_model_defaults and test_diffusion_minimax_h3_image_default_size (status-read count): both fail locally on the merge base and pass on current main, so they come from the stale base.
    • test_diffusion_lora loader check: diffusers isn't installed in that job.
    • tests/test_tp_native_oracle.py (phi3 / fused qkv GQA layout): fails the same way on current main.
    • FSDP2 activation-checkpointing test: passes locally on both head and main; it's training code this PR doesn't touch.
    • Core zoo test_gemma4_packed_documents numeric equality: unsloth-zoo training code, not touched here.
    • Every Studio API/chat/GGUF inference job passed, including Repo tests (CPU, studio).
  • Changed in this round: the one commit da3c514 (described above). No main merge was needed, since main is only 16 ahead and doesn't conflict.

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Verified live against a real ollama create model, and Codex is clean on da3c514. The two lint failures come from main (#18070) and are fixed there by #18086.

@Lyxot
Lyxot merged commit f8c8943 into unslothai:main Nov 17, 2026
danielhanchen added a commit that referenced this pull request Nov 17, 2026
… fixed 0.1 s sleep (#18103)

`studio/backend/tests/test_anthropic_admission.py` fails intermittently
in the Studio `a-f` shard on unrelated PRs (#18045, #18006, #18069,
#18075):

```
test_non_streaming_queued_then_admitted
E   AssertionError: assert 0 == 1
E    +  where 0 = LlamaAdmissionSnapshot(..., capacity=1, active=1, queued=0, ...).queued
test_capacity_enforced_from_effective_parallel_slots
E   AssertionError: assert (3 == 3 and 3 == 3 and 0 == 1)
```

## Cause

Each of these tests occupies every slot, starts a request as a task,
sleeps a fixed 0.1 s and then expects the request to be in the admission
queue. On a loaded runner the handler sometimes has not reached the
queue within 0.1 s, so the snapshot still shows `queued=0`. The
admission code is not at fault; the test raced it.

## Fix

`_until_queued(task)` polls the queue snapshot every 10 ms until the
request is queued, for up to 5 s. It still fails if the request finishes
without ever queueing (`task.done()`) or never queues within the
deadline, so a request that skips admission is still caught. It replaces
the fixed sleep at all five sites that assert `queued == 1` right after
starting the task. The assertions themselves are unchanged.

## Verification

- `tests/test_anthropic_admission.py`: 39 passed, twice.
- Slow handler simulated locally (`await asyncio.sleep(0.25)` at the top
of `anthropic_messages`, not committed):
- main: the five queued checks fail (plus
`test_uncontended_hot_path_is_fast`, which is meant to catch a slow
handler).
  - this branch: only `test_uncontended_hot_path_is_fast` fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants