Port the Llama and Qwen open weights

This commit is contained in:
Thorsten Sommer 2026-09-11 21:35:47 +02:00
parent 402da2da96
commit 9c65ab6c62
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
7 changed files with 338 additions and 13 deletions

View File

@ -8,11 +8,12 @@ namespace AIStudio.Models.Alibaba;
/// The Qwen models Alibaba Cloud Model Studio serves.
/// </summary>
/// <remarks>
/// Everything in this folder is bound to Alibaba Cloud, and that is the point of it. Model Studio
/// sells commercial models -- qwen-max, qwen3.7-max, qwq-plus -- which carry the family names of
/// the open weights without being them, and it answers differently for several names the open
/// weights share with it. The old rules kept the two apart by having two functions; here they are
/// kept apart by saying which provider a rule speaks for.
/// Everything called Model Studio here is bound to Alibaba Cloud, and that is the point of it.
/// Model Studio sells commercial models -- qwen-max, qwen3.7-max, qwq-plus -- which carry the
/// family names of the open weights without being them, and it answers differently for several
/// names the open weights share with it. The old rules kept the two apart by having two functions;
/// here they are kept apart by saying which provider a rule speaks for. The unbound families next
/// to these are the open weights, which answer everywhere else.
///
/// The first rule is the catalog's own fallback, and it is written as a plain substring on purpose:
/// a substring is the weakest thing a rule can be, so every other rule here beats it without anyone

View File

@ -0,0 +1,77 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Alibaba;
/// <summary>
/// Qwen as everybody except Alibaba Cloud serves it: the open weights.
/// </summary>
/// <remarks>
/// The counterpart to the Model Studio families next door, and the reason those are bound to their
/// provider. Alibaba sells commercial models under the same family names, and for several of them
/// it promises something else than the published checkpoint does. Nothing here is bound: these
/// rules answer wherever the weights are run, which is every gateway and every engine somebody
/// starts on their own machine.
///
/// The whole line calls functions, from Qwen 2.5 on, and the Coder checkpoints are built for
/// exactly that. Thinking is not promised by the fallback: the older generations cannot do it, and
/// which of the newer ones think by default differs per checkpoint, so those say it one by one.
/// </remarks>
public sealed class QwenFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.ALIBABA;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/Qwen", new DateOnly(2026, 9, 11), "Ported unchanged from the Qwen block of ProviderExtensions.OpenSource.cs, which is the one answering everywhere but Alibaba Cloud.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder)
{
//
// A substring, because the version grows straight out of the family name: there is no name
// part "qwen" in "qwen2.5-72b-instruct". It is also the weakest thing a rule can be, which
// is what lets every rule below beat it without anybody arranging an order.
//
builder.Rule("qwen").AsSubstring()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
// The VL checkpoints are the ones built to look at pictures:
builder.Rule("qwen").AsSubstring().AlsoContains("vl").Inherits()
.Capabilities(MULTIPLE_IMAGE_INPUT);
// Qwen 3.5 sees, and thinks when the request asks it to:
builder.Rule("qwen3.5").AsPrefix()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.OPTIONAL);
builder.Rule("qwen3.6").AsPrefix().Inherits()
.Reasoning(ReasoningSupport.ON_BY_DEFAULT);
//
// The 3.8 tier without a size is the 27B checkpoint: that is what a rolling tag such as
// "qwen3.8:latest" resolves to, so it is what the tier may promise.
//
builder.Rule("qwen3.8").AsPrefix().InheritsFrom("qwen3.6");
// Flash-Next is the published checkpoint and Flash the production model; both watch videos:
builder.Rule("qwen3.8-flash").AsPrefix().InheritsFrom("qwen3.8")
.Capabilities(VIDEO_INPUT);
//
// Blablador writes the 27B checkpoint in two further ways, and no normalization turns
// either into the canonical name: it separates the family from the version ("Qwen 3.8-27B
// with DFlash on haicluster"), and its short alias drops the dot ("alias-qwen38-27b").
//
builder.Rule("qwen-3.8-27b").AsSegment().InheritsFrom("qwen3.8");
builder.Rule("qwen38-27b").AsSegment().InheritsFrom("qwen3.8");
// The big 3.8 checkpoint reads nothing but text, and it thinks whatever it is asked:
builder.Rule("qwen3.8-2.4t-a95b").AsPrefix()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ALWAYS);
}
}

View File

@ -0,0 +1,31 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Alibaba;
/// <summary>
/// QwQ as everybody except Alibaba Cloud serves it: the open weights built on Qwen 2.5.
/// </summary>
/// <remarks>
/// The other half of the contradiction the provider-bound rules exist for. What Model Studio sells
/// as "qwq-plus" is a commercial model; QwQ-32B, which the gateways and the local engines serve, is
/// the published checkpoint. The two share a family name and nothing else.
///
/// Both answer the same here, and for the same reason: neither the model card nor Alibaba's list of
/// models which call functions mentions tools at all. Anybody who knows better says so in the
/// expert settings.
/// </remarks>
public sealed class QwqFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.ALIBABA;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/Qwen/QwQ-32B", new DateOnly(2026, 9, 11), "Ported unchanged from the QwQ check of ProviderExtensions.OpenSource.cs: text in, text out, thinking which cannot be switched off, and no tools.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("qwq").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ALWAYS);
}

View File

@ -0,0 +1,62 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Meta;
/// <summary>
/// Llama, from the text-only generations to the natively multimodal 4 line.
/// </summary>
/// <remarks>
/// Every rule here is written as a substring, which no other family needs and this one cannot do
/// without. The same checkpoint arrives as "llama3.1", as "meta-llama-3.1", and as "llama-v3p1",
/// because Fireworks writes a version with a "p" where the dot belongs. There is no name part all
/// three share to anchor a rule to, so the three spellings are stated as three rules.
///
/// What decides is the generation: 3.1 was the first Llama trained to call functions, which is why
/// the rules carrying the dot are the ones stating it. "llama3" without a dot is Llama 3.0 and does
/// not get it -- the dot in the pattern is what keeps the two apart.
/// </remarks>
public sealed class LlamaFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.META;
/// <inheritdoc />
public override ModelSource Source => new("https://www.llama.com/docs/model-cards-and-prompt-formats/", new DateOnly(2026, 9, 11), "Ported unchanged from the Llama block of ProviderExtensions.OpenSource.cs.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder)
{
// Whatever else a Llama is, it reads and writes text:
builder.Rule("llama").AsSubstring()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT)
.Apis(CHAT_COMPLETION_API);
//
// The 3.2 vision checkpoints look at pictures and were never trained for tools. The word
// sits wherever the provider puts it -- "llama3.2-vision:11b" on Ollama, but
// "Llama-3.2-11B-Vision-Instruct" on the hub -- so there is nothing to anchor to here
// either, and the generations below have to step aside for it by name.
//
builder.Rule("llama").AsSubstring().AlsoContains("vision")
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT)
.Apis(CHAT_COMPLETION_API);
// From 3.1 on, Llama calls functions. Three spellings, one statement:
builder.Rule("llama3.").AsSubstring().NotContains("vision")
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
builder.Rule("llama-3.").AsSubstring().NotContains("vision").Inherits();
builder.Rule("llama-v3p").AsSubstring().NotContains("vision").Inherits();
// The 4 line was trained on text and images together, so every one of them sees:
builder.Rule("llama4").AsSubstring()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
builder.Rule("llama-4").AsSubstring().Inherits();
builder.Rule("llama-v4").AsSubstring().Inherits();
}
}

View File

@ -0,0 +1,30 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Meta;
/// <summary>
/// Muse, the Meta models whose names do not say Llama.
/// </summary>
/// <remarks>
/// That is the whole reason this is a family of its own: nothing about "muse-glimmer-30b" tells the
/// Llama rules that Meta built it, and a rule for one name is cheaper than teaching them.
///
/// Glimmer always thinks. Its chat template opens the thinking channel whatever the request says,
/// and only the strength of the thinking can be turned down, so there is no mode in which it
/// answers straight away.
/// </remarks>
public sealed class MuseFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.META;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/meta-llama", new DateOnly(2026, 9, 11), "Ported unchanged from the Muse block of ProviderExtensions.OpenSource.cs.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("muse-glimmer").AsSegment()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ALWAYS);
}

View File

@ -0,0 +1,42 @@
using AIStudio.Provider;
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.OpenWeights;
/// <summary>
/// Base checkpoints, whatever family they come from.
/// </summary>
/// <remarks>
/// A base checkpoint is the model before anybody taught it to answer: it continues a text, it knows
/// no chat template, and there is nothing in it that a tool definition could reach. Which family it
/// belongs to changes none of that, which is why this states a modifier rather than a rule of its
/// own -- the family says what the model is, and this takes away what the instruction tuning would
/// have added.
///
/// Reading pictures goes with it. The vision tower may well be there, but without a template there
/// is no way to hand an image to it, so promising the chat that it can send one would be a promise
/// nobody can keep.
///
/// The name part has to be exactly "base", so that a model whose name merely carries the word, as
/// in "based", is left alone.
/// </remarks>
public sealed class BaseCheckpointFamily : ModelFamily
{
private const Capability WHAT_THE_INSTRUCTION_TUNING_WOULD_HAVE_ADDED =
SINGLE_IMAGE_INPUT | MULTIPLE_IMAGE_INPUT | AUDIO_INPUT | SPEECH_INPUT | VIDEO_INPUT |
AUDIO_OUTPUT | IMAGE_OUTPUT | SPEECH_OUTPUT | VIDEO_OUTPUT |
FUNCTION_CALLING | WEB_SEARCH;
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.UNKNOWN;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/docs/transformers/en/chat_templating", new DateOnly(2026, 9, 11), "Ported unchanged from the base checkpoint check of ProviderExtensions.OpenSource.cs, which answers before any family is asked.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Modifier("base").AsSegment()
.Removes(WHAT_THE_INSTRUCTION_TUNING_WOULD_HAVE_ADDED)
.Reasoning(ReasoningSupport.NONE);
}

View File

@ -1,3 +1,4 @@
using AIStudio.Models;
using AIStudio.Models.Registry;
using AIStudio.Provider;
using AIStudio.Tests.Models.Corpus;
@ -13,8 +14,9 @@ namespace AIStudio.Tests.Models;
/// old answer wrong, and there they have to answer what was written down instead. Anything else is
/// either a porting mistake or a decision somebody has to make on purpose and record.
///
/// The list below is what grows. A provider not on it is simply not compared yet: its models reach
/// rules which have not been written, and holding them to anything would only say that.
/// The two lists below are what grow. A provider not on either is simply not compared yet: its
/// models reach rules which have not been written, and holding them to anything would only say
/// that.
/// </remarks>
[TestFixture]
public sealed class PortingDifferenceTests
@ -39,15 +41,51 @@ public sealed class PortingDifferenceTests
LLMProviders.X,
];
/// <summary>
/// The vendors whose models the rebuilt rules already answer for, whoever serves them.
/// </summary>
/// <remarks>
/// Open weights are the reason this list exists next to the one above. They arrive through the
/// gateways and the local engines, and none of those can be called ported until every vendor
/// they carry is. The vendor is the unit the porting actually proceeds in: as soon as the Llama
/// rules exist, every Llama of the corpus is compared, whichever gateway it came from.
///
/// It is also what finally holds the cloud vendors to their models on somebody else's gateway,
/// which the provider list alone never reached: a Claude at GWDG and a DeepSeek distill at
/// OpenRouter are compared here, not at Anthropic and not at DeepSeek.
///
/// Only vendors, never UNKNOWN: that is what a model nobody wrote a rule for answers with, and
/// putting it here would compare everything against everything.
///
/// Mistral is the one ported vendor still missing. Its cloud writes a release date into every
/// name and its rules are built on that, while the open weights are called
/// "mistral-small-3.1-24b-instruct" and carry none -- so those names are still to be ported.
/// </remarks>
private static readonly IReadOnlyList<ModelVendor> VENDORS_ALREADY_PORTED =
[
ModelVendor.OPEN_AI,
ModelVendor.ANTHROPIC,
ModelVendor.GOOGLE,
ModelVendor.ALIBABA,
ModelVendor.DEEP_SEEK,
ModelVendor.PERPLEXITY,
ModelVendor.XAI,
ModelVendor.META,
];
/// <summary>
/// Who built the models of each family, by the name its rules name as their origin.
/// </summary>
private static readonly IReadOnlyDictionary<string, ModelVendor> VENDOR_OF_FAMILY = ModelRegistry.Shared.Families.ToDictionary(family => family.Name, family => family.Vendor, StringComparer.Ordinal);
[Test]
public void EveryPortedModelGetsExactlyTheAnswerItGetsToday()
{
var compared = PortedEntries().Where(entry => !IsKnownToBeWrong(entry)).ToList();
var compared = ComparableEntries().Where(entry => !IsKnownToBeWrong(entry)).ToList();
Assert.Multiple(() =>
{
Assert.That(compared, Is.Not.Empty, "Nothing was compared at all, which would make this test green for the wrong reason.");
foreach (var entry in compared)
{
var today = CapabilitySnapshot.Describe(CapabilitySnapshot.AskTheCurrentRules(entry));
@ -61,7 +99,7 @@ public sealed class PortingDifferenceTests
[Test]
public void EveryPortedModelTheAuditFoundWrongIsNowAnsweredTheWayItShouldBe()
{
var ported = ExpectedChanges.ENTRIES.Where(change => PROVIDERS_ALREADY_PORTED.Contains(change.Provider)).ToList();
var ported = ExpectedChanges.ENTRIES.Where(change => IsCompared(change.Provider, change.ModelId)).ToList();
Assert.Multiple(() =>
{
@ -85,17 +123,35 @@ public sealed class PortingDifferenceTests
// profile, and where the old answer was empty too, the comparison is happy -- while the
// model has in fact disappeared from the rules. This is the test which notices.
//
var named = PortedEntries().Where(entry => !string.IsNullOrWhiteSpace(entry.ModelId)).ToList();
// Only the ported providers, and on purpose: a model is on the vendor list exactly because
// a rule answered for it, so asking those the same question would answer itself.
//
var named = EntriesOfPortedProviders().Where(entry => !string.IsNullOrWhiteSpace(entry.ModelId)).ToList();
Assert.Multiple(() =>
{
Assert.That(named, Is.Not.Empty, "Nothing was asked about at all, which would make this test green for the wrong reason.");
foreach (var entry in named)
Assert.That(ModelRegistry.Shared.Explain(entry.Provider, entry.ModelId).IsKnown, Is.True, $"No rule answers for {entry.Provider} \"{entry.ModelId}\".");
});
}
[Test]
public void NoModelOfTheCorpusIsClaimedByTwoRulesWithTheSameRight()
{
//
// The whole corpus, ported or not: a tie needs two rules that both exist, so every name is
// worth asking about as soon as anything answers for it. This is where a family which
// repeats what another one already said shows up -- reading the rules alone cannot find
// that, because the two patterns are written differently and only meet on a real name.
//
Assert.Multiple(() =>
{
foreach (var entry in ModelCorpus.ENTRIES)
{
var resolution = ModelRegistry.Shared.Explain(entry.Provider, entry.ModelId);
Assert.That(resolution.IsKnown, Is.True, $"No rule answers for {entry.Provider} \"{entry.ModelId}\".");
Assert.That(resolution.IsAmbiguous, Is.False, $"{entry.Provider} \"{entry.ModelId}\" is claimed by {resolution.Selector} and, just as strongly, by {string.Join(", ", resolution.TiedSelectors)}.");
}
});
@ -105,7 +161,33 @@ public sealed class PortingDifferenceTests
/// Every corpus entry of a provider which has been ported, known-wrong ones included.
/// </summary>
/// <returns>The entries.</returns>
private static IEnumerable<CorpusEntry> PortedEntries() => ModelCorpus.ENTRIES.Where(entry => PROVIDERS_ALREADY_PORTED.Contains(entry.Provider));
private static IEnumerable<CorpusEntry> EntriesOfPortedProviders() => ModelCorpus.ENTRIES.Where(entry => PROVIDERS_ALREADY_PORTED.Contains(entry.Provider));
/// <summary>
/// Every corpus entry the rebuilt rules are already meant to answer for.
/// </summary>
/// <returns>The entries.</returns>
private static IEnumerable<CorpusEntry> ComparableEntries() => ModelCorpus.ENTRIES.Where(entry => IsCompared(entry.Provider, entry.ModelId));
/// <summary>
/// Whether the rebuilt rules are held to what the old ones answer for this model.
/// </summary>
/// <param name="provider">Who serves the model.</param>
/// <param name="modelId">The model ID as that provider reports it.</param>
/// <returns>True, when the two answers have to agree.</returns>
private static bool IsCompared(LLMProviders provider, string modelId) => PROVIDERS_ALREADY_PORTED.Contains(provider) || VENDORS_ALREADY_PORTED.Contains(VendorAnswering(provider, modelId));
/// <summary>
/// Whose rules answered for a model, as far as any did.
/// </summary>
/// <param name="provider">Who serves the model.</param>
/// <param name="modelId">The model ID as that provider reports it.</param>
/// <returns>The vendor of the family whose rule chose, or UNKNOWN when none did.</returns>
private static ModelVendor VendorAnswering(LLMProviders provider, string modelId)
{
var selector = ModelRegistry.Shared.Explain(provider, modelId).Selector;
return selector is null ? ModelVendor.UNKNOWN : VENDOR_OF_FAMILY.GetValueOrDefault(selector.Origin, ModelVendor.UNKNOWN);
}
/// <summary>
/// Whether the audit found the current answer for this entry wrong.