Skip to content

Fix Apertus Instruct model mapper pointing at the base upstream repo - #7339

Merged
oobabooga merged 1 commit into
unslothai:mainfrom
vineethsaivs:fix/apertus-instruct-upstream-mapping
Aug 24, 2026
Merged

oobabooga merged 1 commit into
unslothai:mainfrom
vineethsaivs:fix/apertus-instruct-upstream-mapping

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

Summary

The two Apertus Instruct entries in __INT_TO_FLOAT_MAPPER (unsloth/models/mapper.py) name the base upstream repo as their original model, even though the key, the Unsloth 16bit name, and the Unsloth 4bit name all refer to the Instruct variant:

"unsloth/Apertus-70B-Instruct-2509-unsloth-bnb-4bit" : (
    "unsloth/Apertus-70B-Instruct-2509",
    "swiss-ai/Apertus-70B-2509",          # base repo, missing "Instruct"
    "unsloth/Apertus-70B-Instruct-2509-unsloth-bnb-4bit",
),

Every other 3-tuple in this table keeps the invariant that the second element is the same model variant as the key, with only the org prefix swapped (e.g. unsloth/granite-4.0-micro to ibm-granite/granite-4.0-micro). These two entries were the only violations.

Why it matters

The build loop wires the upstream name (values[1]) into both FLOAT_TO_INT_MAPPER and MAP_TO_UNSLOTH_16bit, so with the wrong value:

  • Loading the base model swiss-ai/Apertus-70B-2509 was silently redirected to the Unsloth Instruct model (unsloth/Apertus-70B-Instruct-2509 / its 4bit quant).
  • The genuine instruct upstream swiss-ai/Apertus-70B-Instruct-2509 was registered nowhere, so it never resolved to the Unsloth-optimized version. Same for the 8B pair.

Reproduction (exec the import-free mapper module, no GPU):

BEFORE:  MAP_TO_UNSLOTH_16bit["swiss-ai/Apertus-70B-2509"]          -> "unsloth/Apertus-70B-Instruct-2509"   (wrong: base -> instruct)
         MAP_TO_UNSLOTH_16bit["swiss-ai/Apertus-70B-Instruct-2509"] -> None                                  (wrong: instruct unregistered)
AFTER:   MAP_TO_UNSLOTH_16bit["swiss-ai/Apertus-70B-2509"]          -> None                                  (base stays as-is)
         MAP_TO_UNSLOTH_16bit["swiss-ai/Apertus-70B-Instruct-2509"] -> "unsloth/Apertus-70B-Instruct-2509"   (correct)

Both swiss-ai/Apertus-70B-2509 (base) and swiss-ai/Apertus-70B-Instruct-2509 (instruct) exist as separate repos on the Hub, so this is a clear typo rather than a naming quirk.

Fix

Point the upstream at the Instruct repo for both the 70B and 8B entries, restoring the table's invariant.

Test

tests/test_apertus_instruct_mapping.py exec's the import-free mapper.py and asserts the instruct upstream resolves to the Unsloth instruct 16bit/4bit models and the base upstream is not redirected to the instruct model. It fails before this change (instruct upstream resolves to None) and passes after. Wired into the Bucket-A CPU CI step, alongside the existing test_gemma_2b_mapper_key.py / test_bad_mappings_redirect.py.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@vineethsaivs
vineethsaivs force-pushed the fix/apertus-instruct-upstream-mapping branch from f85b86a to aeb7161 Compare August 3, 2026 16:58
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Rebased onto main; mergeable again. The two mapper entries this PR corrects are unchanged upstream, so the conflict was context drift: a duplicate llama-2-7b-chat key was removed higher up in mapper.py, and three tests were added to the Bucket-A list in the CI workflow. Reapplied both edits on current main, kept the new Bucket-A entries and appended this PR's test after them, and bumped the two "17 Bucket-A tests" counters to 18.

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Pushed 7eeb607 for the one red that was actually mine, and controlled the rest.

tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding landed upstream while this PR was open and requires every checked-in file read in the test trees to pass encoding="utf-8". This PR's test reads mapper.py to exec it, so it needed one; the rebase onto current main is what surfaced it. Fixed.

The other reds are not from this change: tests/studio/test_model_picker_contracts.py (two listGgufVariants contract assertions) and Chat UI Tests fail the same way on other open PRs that touch nothing in common with this one, for example #7864, which is a studio change by a different author and shows the same Chat UI Tests plus Python-matrix reds. This PR touches unsloth/models/mapper.py, one new test, and the Bucket-A list in the CI workflow, none of which the studio UI contracts read.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 5e9fcfb533

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@oobabooga

Copy link
Copy Markdown
Member

The 8B entry is correct: unsloth/Apertus-8B-Instruct-2509 exists, so the redirect resolves as described. The 70B entry is a different case: unsloth/Apertus-70B-Instruct-2509 returns 401 on the Hub (only the 70B GGUF and -unsloth-bnb-4bit repos are published), so after this change a 16bit load of swiss-ai/Apertus-70B-Instruct-2509 resolves through MAP_TO_UNSLOTH_16bit at loader_utils.py:160 to a repo that is not there, where on main it loads from upstream. Can the 70B entry wait until that repo is published, or point its 16bit element at a name that resolves?

@vineethsaivs

Copy link
Copy Markdown
Contributor Author

You are right, and I checked it against the Hub rather than take it on trust: unsloth/Apertus-8B-Instruct-2509 is 200, unsloth/Apertus-70B-Instruct-2509 is 401, and only -GGUF and -unsloth-bnb-4bit are published at 70B.

Fixed in 6b46f431, but not by waiting, because that name is already unreachable on main today. I built the mappers from main, from this PR before the fix, and from this PR after it, and resolved every Apertus value against the Hub API:

main:  MAP_TO_UNSLOTH_16bit[swiss-ai/Apertus-70B-2509]                        -> unsloth/Apertus-70B-Instruct-2509   401
       MAP_TO_UNSLOTH_16bit[unsloth/Apertus-70B-Instruct-2509-unsloth-bnb-4bit] -> unsloth/Apertus-70B-Instruct-2509 401
       INT_TO_FLOAT_MAPPER[unsloth/Apertus-70B-Instruct-2509-unsloth-bnb-4bit]  -> unsloth/Apertus-70B-Instruct-2509 401

this PR (before the fix): the same three, plus the one you spotted
       MAP_TO_UNSLOTH_16bit[swiss-ai/Apertus-70B-Instruct-2509]              -> unsloth/Apertus-70B-Instruct-2509   401

after the fix: every Apertus lookup resolves

So a 16bit load of the base swiss-ai/Apertus-70B-2509 is already redirected into a 401 on main; my first patch moved which upstream name landed on it rather than removing it. Thanks for catching that.

The fix takes your second option, and mapper.py already has a convention for it. Fourteen rows whose model is too large for a 16bit Unsloth repo are 1-tuples naming the real upstream, including unsloth/llama-3-70b-Instruct-bnb-4bit, unsloth/Qwen2-70B-Instruct-bnb-4bit and unsloth/Meta-Llama-3.1-405B-Instruct-bnb-4bit. The 70B Apertus row now matches:

    # No Unsloth 16bit repo exists at this size, so this is a 1-tuple naming the
    # real upstream, same as the other 70B and 405B rows.
    "unsloth/Apertus-70B-Instruct-2509-unsloth-bnb-4bit" : (
        "swiss-ai/Apertus-70B-Instruct-2509",
    ),

values[0] no longer starts with unsloth, so the build loop adds no MAP_TO_UNSLOTH_16bit entries for that row at all and 16bit loads stay on upstream, which is the behaviour you asked to preserve. FLOAT_TO_INT_MAPPER["swiss-ai/Apertus-70B-Instruct-2509"] still reaches the dynamic 4bit repo, so the 4bit path is unaffected, and INT_TO_FLOAT_MAPPER for the 4bit key now returns the upstream instruct repo instead of the 401 name.

The 8B row keeps its full 3-tuple and its 16bit redirect, since that repo exists.

I also added a second test that asserts no entry in any of the three mappers resolves to unsloth/Apertus-70B-Instruct-2509, so this cannot come back silently if the repo list changes again. It fails on current main and on the previous revision of this PR, and passes now. If that 16bit repo does get published later, restoring the 3-tuple is a one-line revert and the test is the thing that will tell you to do it.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed against main at unsloth/models/mapper.py:1119-1127, where the Apertus Instruct rows still name the base swiss-ai repos so a base load resolves to the Unsloth instruct weights, and the 70B row now follows the existing 1-tuple convention. One check, Security audit pip scan-packages :: extras, is green on main but red here, so please take a look at that before we review.

Slot 1 of an __INT_TO_FLOAT_MAPPER entry names the upstream repo the Unsloth
build mirrors, and mapper.py turns it into FLOAT_TO_INT_MAPPER[upstream] and
MAP_TO_UNSLOTH_16bit[upstream]. Both Apertus rows named the pretrained BASE
repo, so loading swiss-ai/Apertus-8B-2509 resolved to the Unsloth Instruct
weights and swiss-ai/Apertus-8B-Instruct-2509 matched nothing at all.

The 70B row is a 1-tuple naming the real upstream, because
unsloth/Apertus-70B-Instruct-2509 is not published; only the GGUF and
-unsloth-bnb-4bit repos exist. That matches the other 70B and 405B rows.

tests/test_apertus_instruct_mapping.py pins both directions and asserts no
Apertus lookup resolves to the unpublished 70B 16bit repo. It is registered in
the Bucket-A list in consolidated-tests-ci.yml, whose count is bumped to match
the list it describes.

Rebased onto current main; the resulting diff is unchanged.
@vineethsaivs
vineethsaivs force-pushed the fix/apertus-instruct-upstream-mapping branch from 6b325e4 to cc81fbd Compare August 19, 2026 18:41
@vineethsaivs

Copy link
Copy Markdown
Contributor Author

Thanks. Looked at it; the short version is that the run predates the current dependency set and I have rebased so it re-runs.

That run is from 2026-07-22, when the branch was cut at 2d231f8, and GitHub has expired its logs (HTTP 410 on the run archive), so there is nothing readable left on it. What I can say without the log is that pip scan-packages :: extras audits the installed dependency set for advisories, and this PR's diff is two string literals in mapper.py, one new test file, and one line added to the Bucket-A list in consolidated-tests-ci.yml. None of that changes a pinned version, an extra, or an install step, so there is no path from this diff to that job's result. The Security audit workflow on main was last green at 14:35 today, which is a month of dependency updates after that run.

So I have rebased onto current main (a6f267a). One commit, same three files, same +81/-7, and the diff is unchanged from what you reviewed. The scan now runs against today's dependency set rather than July's.

One thing in the diff worth flagging so it does not read as a miscount: the Bucket-A comment goes 17 to 21. main's number was already behind its own list, which currently names 20 files; this PR adds tests/test_apertus_instruct_mapping.py to it, so 21 is the count of the list as it will stand. I counted the list rather than trusting the comment.

Separately, and my mistake: I opened #9311 earlier today against these same two rows, having scanned main and not checked for an existing PR on the file. I have closed it and pointed at this one. It was also the worse change: it kept unsloth/Apertus-70B-Instruct-2509 in slot 0, which is exactly the unpublished-repo regression @oobabooga caught here and which this PR's 1-tuple avoids.

@danielhanchen

Copy link
Copy Markdown
Member

Re-checked at the current head: the 8B row now names the real instruct upstream and the 70B row follows the existing 1-tuple convention, so no Apertus lookup lands on the unpublished 16bit repo.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: cc81fbdd28

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

@oobabooga

Copy link
Copy Markdown
Member

Confirmed the Apertus base names no longer redirect to Instruct weights. The 8B Instruct path reaches the published Unsloth models, while 70B preserves the Swiss AI 16-bit upstream and still maps to the published dynamic 4-bit repo.

@oobabooga
oobabooga merged commit 599c93f into unslothai:main Aug 24, 2026
40 of 43 checks passed
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