Archived
core: an architecture plugin can decline imported checkpoints
An imported quantisation names its tool, which no plugin claims, so the family's one quantised plugin serves it and two are refused. rad_arch_serves_imports(), optional and absent = yes, lets a second quantised plugin that reads only its own containers return 0: the import pick then leaves it out of the family, neither counted nor picked as the only plugin. Its own descriptor still selects it. Additive export; RAD_ABI_VERSION does not move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f706caecec
commit
0b0403603b
10 files changed
+55
-5
No files matched your search
@@ -926,6 +926,14 @@ const char* rad_arch_id(void);
|
|||||||
* served at: (unquantised)". */
|
* served at: (unquantised)". */
|
||||||
const char* rad_arch_quant(void);
|
const char* rad_arch_quant(void);
|
||||||
|
|
||||||
|
/* Whether this plugin may serve a checkpoint whose quantisation was imported weight by weight
|
||||||
|
* (Quark, ParoQuant, GPTQ, NVFP4, ...). Such a descriptor names the producing tool, which no plugin
|
||||||
|
* claims, so the family's one quantised plugin serves it, and two are refused (startup.h). A
|
||||||
|
* family's second quantised plugin that reads only its own containers returns 0 and leaves imports
|
||||||
|
* to the first. Optional: absent or non-zero is yes. Additive export; RAD_ABI_VERSION does not
|
||||||
|
* move. */
|
||||||
|
int rad_arch_serves_imports(void);
|
||||||
|
|
||||||
/* What the plugin can say before it declares anything. Optional: a plugin that does not export
|
/* What the plugin can say before it declares anything. Optional: a plugin that does not export
|
||||||
* it answers zero to everything, each field's default.
|
* it answers zero to everything, each field's default.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1331,6 +1331,11 @@ inline int drafter_kv_group(RadBuilder* b, Names& nm, const RadBuildCtx* ctx, Ge
|
|||||||
return NS::audio_format(m); \
|
return NS::audio_format(m); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Optional: RAD_ARCH_SERVES_IMPORTS(0) keeps a family's second quantised plugin out of the pick for
|
||||||
|
* an imported checkpoint (rad_builder.h, rad_arch_serves_imports). */
|
||||||
|
#define RAD_ARCH_SERVES_IMPORTS(V) \
|
||||||
|
extern "C" int rad_arch_serves_imports(void) { return V; }
|
||||||
|
|
||||||
} /* namespace arch */
|
} /* namespace arch */
|
||||||
} /* namespace rad */
|
} /* namespace rad */
|
||||||
|
|
||||||
|
|||||||
@@ -173,11 +173,13 @@ int rad_tools_load_plugins(const std::string& home, const std::vector<std::strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* An imported quantisation is served by the family's quantised plugin (startup.h). */
|
/* An imported quantisation is served by the family's quantised plugin (startup.h). A plugin
|
||||||
|
* that declines imports (rad_arch_serves_imports) is left out of the family here: neither
|
||||||
|
* counted as a second quantised plugin nor picked as the only one. */
|
||||||
if (imported && !arch_id.empty() && out->arch_plugin.empty()) {
|
if (imported && !arch_id.empty() && out->arch_plugin.empty()) {
|
||||||
std::vector<const Plugin*> fam, quantised;
|
std::vector<const Plugin*> fam, quantised;
|
||||||
for (const Plugin& p : r.plugins())
|
for (const Plugin& p : r.plugins())
|
||||||
if (p.kind == RAD_PLUGIN_ARCH && p.arch_id == arch_id) {
|
if (p.kind == RAD_PLUGIN_ARCH && p.arch_id == arch_id && p.arch_serves_imports) {
|
||||||
fam.push_back(&p);
|
fam.push_back(&p);
|
||||||
if (!p.arch_quant.empty()) quantised.push_back(&p);
|
if (!p.arch_quant.empty()) quantised.push_back(&p);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ std::string rad_home_file(const std::string& home, const std::string& rel);
|
|||||||
* `imported`: the checkpoint's quantisation is imported weight by weight (Checkpoint::imports), so
|
* `imported`: the checkpoint's quantisation is imported weight by weight (Checkpoint::imports), so
|
||||||
* its descriptor names the producing tool and no plugin claims it. The family's quantised plugin
|
* its descriptor names the producing tool and no plugin claims it. The family's quantised plugin
|
||||||
* serves it: the one plugin claiming a descriptor, or the only plugin if none does. Two quantised
|
* serves it: the one plugin claiming a descriptor, or the only plugin if none does. Two quantised
|
||||||
* plugins are refused by name. `out->arch_quant` is the chosen descriptor, which a container
|
* plugins are refused by name. A plugin whose rad_arch_serves_imports returns 0 is left out of
|
||||||
|
* both counts. `out->arch_quant` is the chosen descriptor, which a container
|
||||||
* converted from it records. */
|
* converted from it records. */
|
||||||
int rad_tools_load_plugins(const std::string& radiance_home,
|
int rad_tools_load_plugins(const std::string& radiance_home,
|
||||||
const std::vector<std::string>& hierarchy,
|
const std::vector<std::string>& hierarchy,
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ int Registry::commit_(Staged& s, int order) {
|
|||||||
* container, which "" means. */
|
* container, which "" means. */
|
||||||
if (auto q_fn = dl_fn<const char* (*)(void)>(s.handle, "rad_arch_quant"))
|
if (auto q_fn = dl_fn<const char* (*)(void)>(s.handle, "rad_arch_quant"))
|
||||||
p.arch_quant = or_empty(q_fn());
|
p.arch_quant = or_empty(q_fn());
|
||||||
|
/* Optional: absent means the plugin may serve an imported quantisation (startup.h). */
|
||||||
|
if (auto i_fn = dl_fn<int (*)(void)>(s.handle, "rad_arch_serves_imports"))
|
||||||
|
p.arch_serves_imports = i_fn() != 0;
|
||||||
|
|
||||||
/* Optional: answers what the core needs before it builds the RadBuildCtx for declare.
|
/* Optional: answers what the core needs before it builds the RadBuildCtx for declare.
|
||||||
* Absent means every answer is zero (rad_builder.h). */
|
* Absent means every answer is zero (rad_builder.h). */
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ struct Plugin {
|
|||||||
int64_t (*arch_text_prepare)(int, const char*, char*, int64_t) = nullptr;
|
int64_t (*arch_text_prepare)(int, const char*, char*, int64_t) = nullptr;
|
||||||
/* Required of a video generator (rad_builder.h); null for every other plugin. */
|
/* Required of a video generator (rad_builder.h); null for every other plugin. */
|
||||||
int64_t (*arch_video_positions)(int, const RadVideoGeom*, float*, int64_t) = nullptr;
|
int64_t (*arch_video_positions)(int, const RadVideoGeom*, float*, int64_t) = nullptr;
|
||||||
|
/* Optional (rad_builder.h, rad_arch_serves_imports); absent is true. False keeps the plugin
|
||||||
|
* out of the pick for an imported checkpoint (startup.h). */
|
||||||
|
bool arch_serves_imports = true;
|
||||||
|
|
||||||
RadPluginCloseFn close = nullptr;
|
RadPluginCloseFn close = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ foreach(q plain fp8 w4)
|
|||||||
RADTEST_ARCHQ_NAME="radtest_archq_${q}"
|
RADTEST_ARCHQ_NAME="radtest_archq_${q}"
|
||||||
RADTEST_ARCHQ_QUANT="${_rad_q}")
|
RADTEST_ARCHQ_QUANT="${_rad_q}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
# A fourth member, quantised but declining imported checkpoints (rad_arch_serves_imports).
|
||||||
|
rad_add_plugin(radtest_archq_w8 testarchq SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/testplugin.cc)
|
||||||
|
target_compile_definitions(radtest_archq_w8 PRIVATE RADTEST_ARCHQ=1
|
||||||
|
RADTEST_ARCHQ_NAME="radtest_archq_w8" RADTEST_ARCHQ_QUANT="w8"
|
||||||
|
RADTEST_ARCHQ_NO_IMPORTS=1)
|
||||||
|
|
||||||
# KV tier transfer test plugin. Unlike the others it computes (byte-row gather and scatter in the
|
# KV tier transfer test plugin. Unlike the others it computes (byte-row gather and scatter in the
|
||||||
# device domain, on host backend memory), so only tests/mem_test.cpp loads it, by path. It calls
|
# device domain, on host backend memory), so only tests/mem_test.cpp loads it, by path. It calls
|
||||||
|
|||||||
@@ -623,6 +623,10 @@ const RadPluginInfo* rad_plugin_info(void) { return &kInfo; }
|
|||||||
const char* rad_arch_id(void) { return RADTEST_ARCH_ID; }
|
const char* rad_arch_id(void) { return RADTEST_ARCH_ID; }
|
||||||
/* The other half of the selection key (spec §2.4); "" is an unquantised container. */
|
/* The other half of the selection key (spec §2.4); "" is an unquantised container. */
|
||||||
const char* rad_arch_quant(void) { return RADTEST_ARCH_QUANT; }
|
const char* rad_arch_quant(void) { return RADTEST_ARCH_QUANT; }
|
||||||
|
#if defined(RADTEST_ARCHQ_NO_IMPORTS)
|
||||||
|
/* Quantised, but never the plugin an imported checkpoint is handed to. */
|
||||||
|
int rad_arch_serves_imports(void) { return 0; }
|
||||||
|
#endif
|
||||||
/* The core loads and identifies architecture plugins; the build component drives them. Neither
|
/* The core loads and identifies architecture plugins; the build component drives them. Neither
|
||||||
* hook is called by anything this test exercises, and declare refuses rather than pretending. */
|
* hook is called by anything this test exercises, and declare refuses rather than pretending. */
|
||||||
int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx) {
|
int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx) {
|
||||||
|
|||||||
@@ -333,6 +333,7 @@ them by that spelling.
|
|||||||
```c
|
```c
|
||||||
const char* rad_arch_id(void); /* "llama" -- what a container's header names */
|
const char* rad_arch_id(void); /* "llama" -- what a container's header names */
|
||||||
const char* rad_arch_quant(void); /* optional: "" unquantised, or the descriptor served */
|
const char* rad_arch_quant(void); /* optional: "" unquantised, or the descriptor served */
|
||||||
|
int rad_arch_serves_imports(void); /* optional: 0 declines an imported quantisation */
|
||||||
int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx);
|
int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadBuildCtx* ctx);
|
||||||
void rad_arch_step(struct RadCtx* c, const struct RadBatch* batch);
|
void rad_arch_step(struct RadCtx* c, const struct RadBatch* batch);
|
||||||
int rad_arch_probe(const RadModelMeta* meta, RadArchProbe* out); /* optional */
|
int rad_arch_probe(const RadModelMeta* meta, RadArchProbe* out); /* optional */
|
||||||
@@ -346,6 +347,11 @@ underscores; `rad-convert --arch ID` overrides it. Every configuration key reach
|
|||||||
`RadModelMeta`, and the plugin's name map says which checkpoint tensor each declared weight comes
|
`RadModelMeta`, and the plugin's name map says which checkpoint tensor each declared weight comes
|
||||||
from, so `rad-convert` needs no knowledge of the model.
|
from, so `rad-convert` needs no knowledge of the model.
|
||||||
|
|
||||||
|
A checkpoint whose quantisation was imported weight by weight (GUIDE §3.2: Quark, ParoQuant, GPTQ,
|
||||||
|
NVFP4) names its producing tool, which no plugin claims; it goes to the family's one quantised
|
||||||
|
plugin, and two are refused by name. A second quantised plugin that reads only its own containers
|
||||||
|
says so with `RAD_ARCH_SERVES_IMPORTS(0)` (`qwen35_w8a8` does), and imports keep their plugin.
|
||||||
|
|
||||||
- **Ops from `docs/OPS.md` run on any library.** An op libref implements has a host fallback, an
|
- **Ops from `docs/OPS.md` run on any library.** An op libref implements has a host fallback, an
|
||||||
oracle and a specification to check kernel libraries against. An op you invent runs only on a
|
oracle and a specification to check kernel libraries against. An op you invent runs only on a
|
||||||
library that implements it.
|
library that implements it.
|
||||||
|
|||||||
+15
-2
@@ -1944,7 +1944,8 @@ TEST(the_home_search_path_splits_on_colons_and_the_first_home_with_a_file_wins)
|
|||||||
* selected by the (id, quantisation) pair, exactly. A checkpoint whose quantisation was imported
|
* selected by the (id, quantisation) pair, exactly. A checkpoint whose quantisation was imported
|
||||||
* weight by weight names its producing tool, which no plugin claims: the family's one quantised
|
* weight by weight names its producing tool, which no plugin claims: the family's one quantised
|
||||||
* plugin serves it (or its only plugin), and two quantised plugins are refused by name rather than
|
* plugin serves it (or its only plugin), and two quantised plugins are refused by name rather than
|
||||||
* chosen between. */
|
* chosen between. A plugin that declines imports (rad_arch_serves_imports, radtest_archq_w8) is
|
||||||
|
* still selected by its own descriptor, but is neither counted nor picked for an import. */
|
||||||
TEST(the_architecture_plugin_is_picked_by_id_and_quantisation) {
|
TEST(the_architecture_plugin_is_picked_by_id_and_quantisation) {
|
||||||
const std::string archq = home() + "/testarchq";
|
const std::string archq = home() + "/testarchq";
|
||||||
NEED_ARTIFACT(archq + "/radtest_archq_fp8.so");
|
NEED_ARTIFACT(archq + "/radtest_archq_fp8.so");
|
||||||
@@ -1978,7 +1979,9 @@ TEST(the_architecture_plugin_is_picked_by_id_and_quantisation) {
|
|||||||
const std::string all = make_home({ "plain", "fp8", "w4" });
|
const std::string all = make_home({ "plain", "fp8", "w4" });
|
||||||
const std::string one = make_home({ "plain", "fp8" });
|
const std::string one = make_home({ "plain", "fp8" });
|
||||||
const std::string bare = make_home({ "plain" });
|
const std::string bare = make_home({ "plain" });
|
||||||
REQUIRE(!all.empty() && !one.empty() && !bare.empty());
|
const std::string w8 = make_home({ "plain", "fp8", "w8" });
|
||||||
|
const std::string plain_w8 = make_home({ "plain", "w8" });
|
||||||
|
REQUIRE(!all.empty() && !one.empty() && !bare.empty() && !w8.empty() && !plain_w8.empty());
|
||||||
|
|
||||||
LoadedPlugins lp;
|
LoadedPlugins lp;
|
||||||
std::string log;
|
std::string log;
|
||||||
@@ -2000,6 +2003,16 @@ TEST(the_architecture_plugin_is_picked_by_id_and_quantisation) {
|
|||||||
CHECK_OK(pick(bare, "quark-mxfp4", true, &lp, &log));
|
CHECK_OK(pick(bare, "quark-mxfp4", true, &lp, &log));
|
||||||
CHECK_EQ(lp.arch_plugin, std::string("radtest_archq_plain"));
|
CHECK_EQ(lp.arch_plugin, std::string("radtest_archq_plain"));
|
||||||
CHECK_EQ(pick(all, "fp8", false, &lp, &log), RAD_OK);
|
CHECK_EQ(pick(all, "fp8", false, &lp, &log), RAD_OK);
|
||||||
|
|
||||||
|
/* A second quantised plugin that declines imports leaves them to the first. */
|
||||||
|
CHECK_OK(pick(w8, "quark-mxfp4", true, &lp, &log));
|
||||||
|
CHECK_EQ(lp.arch_plugin, std::string("radtest_archq_fp8"));
|
||||||
|
CHECK(!has(log, "more than one quantised plugin"));
|
||||||
|
CHECK_OK(pick(w8, "w8", false, &lp, &log));
|
||||||
|
CHECK_EQ(lp.arch_plugin, std::string("radtest_archq_w8"));
|
||||||
|
CHECK_EQ(lp.arch_quant, std::string("w8"));
|
||||||
|
CHECK_OK(pick(plain_w8, "quark-mxfp4", true, &lp, &log));
|
||||||
|
CHECK_EQ(lp.arch_plugin, std::string("radtest_archq_plain"));
|
||||||
rad_tools_registry().close();
|
rad_tools_registry().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user