hf: a lone container does not outrank weights beside it

Give --model org/repo and the engine picks what to serve from the fetched
directory: one .rad on the top level won outright, whatever else was
there -- and .rad was not in the skip list a safetensors set imposes on
.bin/.pth/.gguf, so hfget fetched the rival too. A repository that ships
a real safetensors set beside one decoy .rad chose for the operator: the
container wins, the engine loads and serves it in place of the model the
operator named.

hf_served_path no longer resolves that tie by rank -- a container among
safetensors or gguf weights is refused by name and the operator passes the
file they mean -- and hfget skips .rad when a safetensors set is present,
as it skips every other rival. A repo holding only a container still
serves it: the fix is against the silent tie-break, not against .rad.
This commit is contained in:
fl0l0u committed 2026-11-15 20:38:10 +00:00
1 parent 4c9a79ca98
commit 965a7caa51
3 files changed
+40 -4

No files matched your search

+15 -3
View File
@@ -97,18 +97,30 @@ std::string hf_default_download_dir() {
std::string hf_served_path(const std::string& dir, std::string* why) {
std::vector<std::string> rad;
int64_t other_fmt = 0;
std::error_code ec;
for (const fs::directory_entry& e : fs::directory_iterator(dir, ec)) {
std::error_code fe;
if (e.is_regular_file(fe) && e.path().filename().string().ends_with(".rad"))
rad.push_back(e.path().filename().string());
if (!e.is_regular_file(fe)) continue;
const std::string name = e.path().filename().string();
if (name.ends_with(".rad")) rad.push_back(name);
/* A repo fetched with hfget holds its source weights beside anything the operator or a
* conversion added later; a container sitting among them is not self-appointing. */
else if (name.ends_with(".safetensors") || name.ends_with(".gguf")) ++other_fmt;
}
if (ec) {
*why = dir + ": " + ec.message();
return std::string();
}
if (rad.empty()) return dir;
if (rad.size() == 1) return dir + "/" + rad[0];
if (rad.size() == 1) {
if (other_fmt > 0) {
*why = dir + " holds the container " + rad[0] + " beside safetensors or gguf weights; " +
"pass the one to serve as --model " + dir + "/<file>";
return std::string();
}
return dir + "/" + rad[0];
}
std::string names;
for (size_t i = 0; i < rad.size(); ++i) names += (i ? ", " : "") + rad[i];
*why = dir + " holds " + std::to_string(rad.size()) + " containers (" + names +
+1 -1
View File
@@ -147,7 +147,7 @@ bad=$(printf '%s' "$listing" | jq -r '[.[] | select(.type == "file")
[ -n "$bad" ] && { echo "hfget: the listing names '$bad', which does not land inside the destination" >&2; exit 1; }
have_st=$(printf '%s' "$listing" | jq '[.[] | select(.path | endswith(".safetensors"))] | length')
sel='.[] | select(.type == "file")'
[ "$have_st" -gt 0 ] && sel="$sel"' | select((.path | test("\\.(bin|msgpack|h5|onnx|onnx_data|gguf)$") or test("(^|/)(pytorch_model|consolidated)[^/]*\\.pth$")) | not)'
[ "$have_st" -gt 0 ] && sel="$sel"' | select((.path | test("\\.(bin|msgpack|h5|onnx|onnx_data|gguf|rad)$") or test("(^|/)(pytorch_model|consolidated)[^/]*\\.pth$")) | not)'
list=$(mktemp "${TMPDIR:-/tmp}/hfget.XXXXXX")
trap 'rm -f "$list" "$dest/.hfget-manifest.tmp"' EXIT INT TERM
+24
View File
@@ -108,6 +108,30 @@ TEST(two_containers_are_refused_by_name) {
CHECK(why.find("--model") != std::string::npos);
}
/* A repo fetched with hfget holds its source weights in the directory; a lone .rad among them
* -- whoever put it there -- must not be served in their place without one word said. The
* engine names the ambiguity instead of resolving it by rank. */
TEST(a_container_beside_other_weights_is_not_served_silently) {
TempDir t;
t.touch("model-00001-of-00002.safetensors");
t.touch("model-00002-of-00002.safetensors");
t.touch("model.safetensors.index.json");
t.touch("decoy.rad");
std::string why;
CHECK_EQ(hf_served_path(t.path, &why), std::string());
CHECK(why.find("decoy.rad") != std::string::npos);
CHECK(why.find("--model") != std::string::npos);
/* gguf competes too, and without any competitor the lone container is still the answer. */
TempDir g;
g.touch("model.gguf");
g.touch("converted.rad");
CHECK_EQ(hf_served_path(g.path, &why), std::string());
TempDir r;
r.touch("qwen.rad");
r.touch("config.json");
CHECK_EQ(hf_served_path(r.path, &why), r.path + "/qwen.rad");
}
TEST(the_download_dir_defaults_to_the_xdg_cache) {
const char* x = std::getenv("XDG_CACHE_HOME");
const std::string saved = x ? x : "";