New models. Thinking Machines' Inkling 2 Mini by gostar (#584-#586): its text backbone and loop, the release's NVFP4 and MXFP8 checkpoint read by the converter, an int8 trunk, the vision tower, tensor parallelism, tool calls (with Warzuponus) and an image processor that matches transformers bit for bit (millaguie). Inkling's routed experts are served in IQR-V4's four-bit trellis (moe_gemm_iqr), fitted by GPTQ against Hessians the plugin now records (`--calib-dir`), its token embedding in int8 (read in place by embed_lookup), and incoai's DFlash2 drafter in four bits in place of the release's DSpark. That container, 14.4 GiB with the vision tower, decodes 190 / 427 / 658 tokens a second at 1 / 4 / 8 streams at tp 2 on two R9700 with `draft-window: adaptive` (code 240 / 550 / 790, step-by-step arithmetic 358 / 811 / 1116): 19-43% ahead of the same target with the release's DSpark drafter and 45-83% ahead of the all-int8 container (26.1 GiB, 124 / 263 / 386), at a mean KL of 0.0066 against the release's weights (int8: 0.0042). DeepSeek-V4.1-Flash on 2.x by baKon (#583), with its vision tower, its IQ1_S and IQ2_XXS containers and linears and experts served in llama.cpp's own blocks; parts ported from mikoskinen/r9700-exact-serving by Dad_Vibes' fork. GLM-5.3-Flash on 2.x with its IQR / IQ8R container, an int8 latent cache and four-card serving by AnimusNull (#566). Gemma 4 dense on EXL3-V3 by keptn42 (#537), on the EXL3 dense rows and qwen35_exl3 tensor parallelism by Hero422. NVIDIA's 2-bit Nemotron-3.5-Bolt-74B-A9B on one card by keptn42 (#477). Wan 2.2 TI2V-5B text-to-video and first-frame video by rkcth (#535). LFM3-1.7B on RDNA3 iGPUs by DokterSmol (#578). Qwen3.8-27B in bf16 with the DFlash2 drafter, and bf16x12, bf16 weights packed losslessly in 12.25 bits, by eddie168 (#577). Int8 experts for drama-3 by morevgalex (#598). Speculative decoding. Draft trees for Qwen3.8-27B's DFlash2 drafts by Kezi (#450, opt-in): one card, +17% at one stream and +14% at two. --draft-max-lanes and --draft-min-accept, two gates on a block drafter, and --draft-window-ckpt, its window KV kept in the checkpoint slots, by rkcth (#600-#602). `draft-window: adaptive` verifies each sequence's drafts up to the first one unlikely to be kept. A verify's rows share each K and V tile in Inkling's attention by gostar (#608): 93 to 118 tokens a second at a 70k-token prompt on one card. Generation. Krea 2 instruction edits with one or two references and registered outfill, LoRA on the image generators with bias deltas and row-mixer adapters applied per request, and MiniMax-H3's model-declared sparse attention profiles, by rkcth (#534, #542, #543, #605-#609). MiniMax-H3's audio reference guide pinned from a frame by 1beb (#595). LTX-2's chunk ceiling raised to 40 by Itoash (#570). Fleets and memory. memory.queue-reserve, the hardware queues a card keeps ready, by kevinjd (#589). memory.pinned-numa-node by Foundry (#580). memory.card-headroom-mib on single-model tensor-parallel budgets by zihaomu (#624). Parked weights rebuilt on the CPU, memory ownership kept across a failed handoff and quiescent callbacks serialised, by rkcth (#557-#561). A warm load may unload a parked model (#592); the first card listed chooses the architecture (#458). Kernels. libr3d's packed dense IQR GEMM and routed IQR expert rows on gfx1100, and libhalo's GEMV decode for Qwen3.8-Flash-Next's MoE down, by zihaomu (#562, #620, #622). GGML IQ2_XXS and IQ3_XXS packed on the card by baKon. Dashboard. KV cache in tokens (in use, capacity now and with all flexible space), live figures through long prefill steps, step / decode / prefill / acceptance lines without holes, and expert hit rates only on tiered models. Seven tile and history defects fixed by Noblistic (#597), vision encoder and per-card hardware figures by davetha (#574), per-LoRA attribution by dowjames (#552). Fixed. return_tokens / return_token_ids on the OpenAI endpoints (#571). reasoning_effort "none" and "minimal" reach a template that takes them as levels, by millaguie (#608). Misaligned loads in the windowed paged attention over an int8 cache (#540). A retired 27B head refused by name (#541). rad-convert's GPU trellis jobs kept fed, and --reuse-only, by gostar (#575). jinja's tojson takes sort_keys by Warzuponus (#582). hfget measures file sizes with stat, by kepler_62f (#623). The tested C++ compiler is stated in the build guide by lowell80 (#551). The codebase was cleaned up: shared helpers instead of repeated blocks, and the int8 linear, activation and GEMM code no longer named after the retired fp8 formats. Inkling 2 Mini is served in one form: IQR-V4 experts with the DFlash2 drafter (StillDeadcode/inkling-2-mini-iq4r-v4 on Hugging Face, or data/recipes/inkling2-mini-iq4r-v4.recipe). A container with the release's DSpark drafter, or with NVFP4, int8 or 4-bit experts, is refused by name and needs converting again. Plugin ABI 44: out-of-tree plugins need to be rebuilt. Thanks to @gostar, @baKon, @Dad_Vibes, @AnimusNull, @keptn42, @Hero422, @rkcth, @DokterSmol, @eddie168, @morevgalex, @Kezi, @1beb, @Itoash, @kevinjd, @Foundry, @zihaomu, @Noblistic, @davetha, @dowjames, @Warzuponus, @millaguie, @kepler_62f, @lowell80 and @Code000.
473 lines
19 KiB
C++
473 lines
19 KiB
C++
/* hf_model_test.cpp -- a --model that names a Hugging Face repo (core/hf_model.h).
|
|
*
|
|
* Both questions are answered before anything is fetched; a wrong answer costs a download or a
|
|
* confusing refusal.
|
|
*
|
|
* Is it a repo a path that exists is never looked up, and a missing model file is reported
|
|
* as missing rather than sent to the hub as a repo name
|
|
* What to serve a model repo holds one container beside a README, a recipe and a licence;
|
|
* a checkpoint repo holds none and is served as the directory
|
|
*
|
|
* No network: where the fetch itself runs (scripts/hfget.sh, from the build tree's libexec/), a
|
|
* `curl` placed first on PATH answers for the hub.
|
|
*/
|
|
#include "rad_test.h"
|
|
|
|
#include "hf_model.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
using namespace rad;
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace {
|
|
|
|
/* An empty directory of its own under the test's temporary directory. */
|
|
struct TempDir {
|
|
std::string path;
|
|
TempDir() : path(radtest::make_tmp_dir("dir")) {}
|
|
void touch(const std::string& name) const {
|
|
if (FILE* f = std::fopen((path + "/" + name).c_str(), "w")) std::fclose(f);
|
|
}
|
|
};
|
|
|
|
} /* namespace */
|
|
|
|
TEST(a_repo_id_is_two_names_of_the_hubs_characters) {
|
|
CHECK(hf_repo_id("StillDeadcode/minicpm5-2b-fp8"));
|
|
CHECK(hf_repo_id("StillDeadcode/qwen3.8-27b-mxfp4"));
|
|
CHECK(hf_repo_id("Qwen/Qwen3.8-Flash-Next"));
|
|
CHECK(hf_repo_id("hf-internal-testing/tiny_random.v2"));
|
|
|
|
CHECK(!hf_repo_id(""));
|
|
CHECK(!hf_repo_id("minicpm5-2b-fp8")); /* no owner */
|
|
CHECK(!hf_repo_id("/abs/model")); /* absolute */
|
|
CHECK(!hf_repo_id("a/b/c")); /* a path, not a repo */
|
|
CHECK(!hf_repo_id("owner/"));
|
|
CHECK(!hf_repo_id("/name"));
|
|
CHECK(!hf_repo_id("../x")); /* a relative path, not a name */
|
|
CHECK(!hf_repo_id("./x"));
|
|
CHECK(!hf_repo_id("owner/.hidden"));
|
|
CHECK(!hf_repo_id("-x/y")); /* would read as an option */
|
|
CHECK(!hf_repo_id("owner/name with space"));
|
|
CHECK(!hf_repo_id("owner/na$me"));
|
|
CHECK(!hf_repo_id("C:/models"));
|
|
}
|
|
|
|
TEST(a_missing_model_file_is_not_sent_to_the_hub) {
|
|
CHECK(!hf_repo_id("models/qwen.rad"));
|
|
CHECK(!hf_repo_id("ckpt/model.safetensors"));
|
|
CHECK(!hf_repo_id("ckpt/model.gguf"));
|
|
CHECK(!hf_repo_id("ckpt/model.safetensors.index.json"));
|
|
}
|
|
|
|
TEST(a_path_that_exists_is_never_a_repo) {
|
|
TempDir t;
|
|
const std::string cwd = fs::current_path().string();
|
|
CHECK_EQ(chdir(t.path.c_str()), 0);
|
|
fs::create_directories("owner/name");
|
|
CHECK(!hf_repo_id("owner/name")); /* exists: a checkpoint directory */
|
|
CHECK(hf_repo_id("owner/other")); /* does not: a repo */
|
|
CHECK_EQ(chdir(cwd.c_str()), 0);
|
|
}
|
|
|
|
TEST(the_one_container_in_a_repo_is_what_is_served) {
|
|
TempDir t;
|
|
t.touch("README.md");
|
|
t.touch("LICENSE");
|
|
t.touch("q38-27b.recipe");
|
|
t.touch(".hfget-manifest");
|
|
std::string why;
|
|
CHECK_EQ(hf_served_path(t.path, &why), t.path); /* no container: a checkpoint */
|
|
|
|
t.touch("qwen3.8-27b-mxfp4.rad");
|
|
CHECK_EQ(hf_served_path(t.path, &why), t.path + "/qwen3.8-27b-mxfp4.rad");
|
|
|
|
fs::create_directories(t.path + "/sub");
|
|
t.touch("sub/other.rad"); /* only the top level counts */
|
|
CHECK_EQ(hf_served_path(t.path, &why), t.path + "/qwen3.8-27b-mxfp4.rad");
|
|
}
|
|
|
|
TEST(two_containers_are_refused_by_name) {
|
|
TempDir t;
|
|
t.touch("a.rad");
|
|
t.touch("b.rad");
|
|
std::string why;
|
|
CHECK_EQ(hf_served_path(t.path, &why), std::string());
|
|
CHECK(why.find("a.rad") != std::string::npos);
|
|
CHECK(why.find("b.rad") != std::string::npos);
|
|
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 : "";
|
|
setenv("XDG_CACHE_HOME", "/c", 1);
|
|
CHECK_EQ(hf_default_download_dir(), std::string("/c/radiance/hf"));
|
|
unsetenv("XDG_CACHE_HOME");
|
|
if (const char* h = std::getenv("HOME"); h && *h)
|
|
CHECK_EQ(hf_default_download_dir(), std::string(h) + "/.cache/radiance/hf");
|
|
if (x) setenv("XDG_CACHE_HOME", saved.c_str(), 1);
|
|
}
|
|
|
|
/* ================================================================== a restart with the hub out of reach */
|
|
namespace {
|
|
|
|
/* Where resolve_hf_model looks for the downloader: libexec/radiance/ beside this binary's
|
|
* directory, where the build copies it. */
|
|
std::string hfget_beside_this_binary() {
|
|
std::error_code ec;
|
|
const fs::path exe = fs::read_symlink("/proc/self/exe", ec);
|
|
return (exe.parent_path() / ".." / "libexec" / "radiance" / "hfget.sh").lexically_normal();
|
|
}
|
|
|
|
bool on_path(const char* tool) {
|
|
const char* path = std::getenv("PATH");
|
|
std::string all = path ? path : "";
|
|
size_t at = 0;
|
|
while (at <= all.size()) {
|
|
size_t c = all.find(':', at);
|
|
if (c == std::string::npos) c = all.size();
|
|
const std::string d = all.substr(at, c - at);
|
|
if (!d.empty() && ::access((d + "/" + tool).c_str(), X_OK) == 0) return true;
|
|
at = c + 1;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* PATH with a directory holding a `curl` script first, restored on destruction. */
|
|
struct FakeCurl {
|
|
TempDir bin;
|
|
std::string saved;
|
|
explicit FakeCurl(const std::string& script) {
|
|
const char* p = std::getenv("PATH");
|
|
saved = p ? p : "";
|
|
const std::string f = bin.path + "/curl";
|
|
if (FILE* o = std::fopen(f.c_str(), "w")) {
|
|
std::fputs(script.c_str(), o);
|
|
std::fclose(o);
|
|
}
|
|
::chmod(f.c_str(), 0755);
|
|
setenv("PATH", (bin.path + ":" + saved).c_str(), 1);
|
|
}
|
|
~FakeCurl() { setenv("PATH", saved.c_str(), 1); }
|
|
};
|
|
|
|
/* A hub that cannot be reached: every request fails as curl does without a network. hfget.sh
|
|
* exits 3 (nothing on disk changed). */
|
|
const char* kOffline = "#!/bin/sh\nexit 6\n";
|
|
/* A hub that lists a file and then fails to send it: hfget.sh exits 1 (a file may be partial). */
|
|
const char* kBrokenTransfer =
|
|
"#!/bin/sh\n"
|
|
"for a in \"$@\"; do case \"$a\" in *api/models*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"new.bin\",\"size\":5}]'; exit 0;; esac; done\n"
|
|
"exit 22\n";
|
|
|
|
} /* namespace */
|
|
|
|
/* hfget.sh exits 3 when it changed nothing on disk, and a copy a complete fetch left (it has the
|
|
* success manifest) is then served, with a warning, so a restart does not need the hub. Without
|
|
* the manifest the copy may be incomplete; after any other failure a file may be partial; either
|
|
* way nothing is served. */
|
|
TEST(a_restart_serves_the_complete_copy_when_the_hub_cannot_be_reached) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
const std::string repo = "radiance-test-owner/radiance-test-model";
|
|
const std::string dest = root.path + "/" + repo;
|
|
fs::create_directories(dest);
|
|
if (FILE* f = std::fopen((dest + "/m.rad").c_str(), "w")) std::fclose(f);
|
|
|
|
auto resolve = [&](std::string* model, std::string* log) {
|
|
Config c;
|
|
c.model = repo;
|
|
c.download_dir = root.path;
|
|
bool ok = false;
|
|
*log = stderr_of([&] { ok = resolve_hf_model(c); });
|
|
*model = c.model;
|
|
return ok;
|
|
};
|
|
std::string model, log;
|
|
{
|
|
FakeCurl curl(kOffline);
|
|
/* No manifest: an interrupted first fetch, refused. */
|
|
CHECK(!resolve(&model, &log));
|
|
CHECK(has(log, "exit 3"));
|
|
|
|
if (FILE* f = std::fopen((dest + "/.hfget-manifest").c_str(), "w")) {
|
|
std::fputs("0\tm.rad\n", f);
|
|
std::fclose(f);
|
|
}
|
|
CHECK(resolve(&model, &log));
|
|
CHECK_EQ(model, dest + "/m.rad");
|
|
CHECK(has(log, "serving the copy fetched before"));
|
|
}
|
|
{
|
|
FakeCurl curl(kBrokenTransfer);
|
|
CHECK(!resolve(&model, &log));
|
|
CHECK(has(log, "exit 1"));
|
|
}
|
|
}
|
|
|
|
/* A hub whose repo holds safetensors beside a torch copy of the same weights and a codec that only
|
|
* ships as a .pth: the copies (pytorch_model*.pth, a pickle .bin) are skipped, the codec is
|
|
* fetched, since the checkpoint reader reads it (core/format/torch_zip.h). */
|
|
const char* kCodecRepo =
|
|
"#!/bin/sh\n"
|
|
"out=''; url=''; prev=''\n"
|
|
"for a in \"$@\"; do\n"
|
|
" [ \"$prev\" = -o ] && out=\"$a\"\n"
|
|
" case \"$a\" in https://*) url=\"$a\";; esac\n"
|
|
" prev=\"$a\"\n"
|
|
"done\n"
|
|
"case \"$url\" in *api/models*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"model.safetensors\",\"size\":3},"
|
|
"{\"type\":\"file\",\"path\":\"codec.pth\",\"size\":3},"
|
|
"{\"type\":\"file\",\"path\":\"pytorch_model.pth\",\"size\":3},"
|
|
"{\"type\":\"file\",\"path\":\"pytorch_model.bin\",\"size\":3}]'; exit 0;; esac\n"
|
|
"[ -n \"$out\" ] && printf abc > \"$out\"\n"
|
|
"exit 0\n";
|
|
|
|
TEST(a_pth_that_is_not_the_weights_again_is_fetched_beside_the_safetensors) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
FakeCurl curl(kCodecRepo);
|
|
const std::string cmd = "sh '" + hfget_beside_this_binary() +
|
|
"' radiance-test-owner/radiance-test-model '" + root.path +
|
|
"' >/dev/null 2>&1";
|
|
CHECK_EQ(std::system(cmd.c_str()), 0);
|
|
CHECK(fs::exists(root.path + "/model.safetensors"));
|
|
CHECK(fs::exists(root.path + "/codec.pth"));
|
|
CHECK(!fs::exists(root.path + "/pytorch_model.pth"));
|
|
CHECK(!fs::exists(root.path + "/pytorch_model.bin"));
|
|
}
|
|
|
|
/* A listing that names a file outside the destination -- absolute, or a `..` segment -- is not
|
|
* a listing of a repo at all, so hfget.sh refuses the whole thing rather than half-obeying it:
|
|
* silently skipping the entry would leave a directory that reads as complete and is not, and
|
|
* the manifest would certify it. */
|
|
const char* kEscapeListing =
|
|
"#!/bin/sh\n"
|
|
"for a in \"$@\"; do case \"$a\" in *api/models*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"../escape.bin\",\"size\":1},"
|
|
"{\"type\":\"file\",\"path\":\"kept.bin\",\"size\":1}]'; exit 0;; esac; done\n"
|
|
"exit 22\n";
|
|
|
|
TEST(a_listing_naming_a_path_outside_the_destination_is_refused) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
FakeCurl curl(kEscapeListing);
|
|
const std::string cmd = "sh '" + hfget_beside_this_binary() +
|
|
"' radiance-test-owner/radiance-test-model '" + root.path +
|
|
"' >/dev/null 2>'" + root.path + "/err'";
|
|
CHECK(std::system(cmd.c_str()) != 0);
|
|
CHECK(!fs::exists(root.path + "/escape.bin"));
|
|
CHECK(!fs::exists(root.path + "/kept.bin")); /* the whole listing is refused */
|
|
CHECK(!fs::exists(root.path + "/.hfget-manifest"));
|
|
std::string err;
|
|
if (FILE* e = std::fopen((root.path + "/err").c_str(), "r")) {
|
|
char buf[256];
|
|
size_t n;
|
|
while ((n = std::fread(buf, 1, sizeof buf - 1, e)) > 0) { buf[n] = '\0'; err += buf; }
|
|
std::fclose(e);
|
|
}
|
|
CHECK(has(err, "does not land inside the destination"));
|
|
}
|
|
|
|
/* `#` and `?` end the URL's path: curl requests the stripped object instead. A listing that
|
|
* spells out a truncated name with the truncated object's size and oid passes every check
|
|
* afterwards -- the bytes arrive under a name nobody asked for, and the manifest certifies the
|
|
* directory complete. Refused as an escaping name is. */
|
|
const char* kFragmentListing =
|
|
"#!/bin/sh\n"
|
|
"for a in \"$@\"; do case \"$a\" in *api/models*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"model.bin#x\",\"size\":1},"
|
|
"{\"type\":\"file\",\"path\":\"kept.bin\",\"size\":1}]'; exit 0;; esac; done\n"
|
|
"exit 22\n";
|
|
|
|
TEST(a_listing_name_that_curl_would_truncate_is_refused_whole) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
FakeCurl curl(kFragmentListing);
|
|
const std::string cmd = "sh '" + hfget_beside_this_binary() +
|
|
"' radiance-test-owner/radiance-test-model '" + root.path +
|
|
"' >/dev/null 2>&1";
|
|
CHECK(std::system(cmd.c_str()) != 0);
|
|
CHECK(!fs::exists(root.path + "/model.bin#x"));
|
|
CHECK(!fs::exists(root.path + "/model.bin")); /* curl would have fetched this one */
|
|
CHECK(!fs::exists(root.path + "/kept.bin")); /* the whole listing is refused */
|
|
CHECK(!fs::exists(root.path + "/.hfget-manifest"));
|
|
}
|
|
|
|
/* The per-file child re-screens its name without waiting for the parent: a trailing `..` (the
|
|
* parent's regex caught it, the child's old case did not) and curl's own path terminators must
|
|
* fail there too, before any request or any write. */
|
|
TEST(the_child_screen_refuses_trailing_dotdot_and_curl_terminator_names) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
TempDir root;
|
|
for (const char* name : {"model.bin#x", "model.bin?y", "sub/.."}) {
|
|
const std::string cmd =
|
|
"HFGET_CHILD=1 HFGET_DEST='" + root.path + "' sh '" + hfget_beside_this_binary() +
|
|
"' \"$(printf '5\\t\\t" + std::string(name) + "')\" >/dev/null 2>&1";
|
|
CHECK(std::system(cmd.c_str()) != 0);
|
|
}
|
|
CHECK(fs::is_empty(root.path));
|
|
}
|
|
|
|
/* An LFS file's oid is the hub's claim about its bytes; the download is kept only once those
|
|
* bytes hash to it -- the size check alone would take a swapped file of the same length, and a
|
|
* spliced resume at any length the hub likes. A mismatch deletes the file and fails the run;
|
|
* a match lands in the manifest, which is what makes "warm" mean verified-warm after. */
|
|
const char* kBadOid =
|
|
"#!/bin/sh\n"
|
|
"out=''; url=''; prev=''\n"
|
|
"for a in \"$@\"; do\n"
|
|
" [ \"$prev\" = -o ] && out=\"$a\"\n"
|
|
" case \"$a\" in https://*) url=\"$a\";; esac\n"
|
|
" prev=\"$a\"\n"
|
|
"done\n"
|
|
"case \"$url\" in *api/models*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"big.bin\",\"size\":10,"
|
|
"\"lfs\":{\"oid\":\"0000000000000000000000000000000000000000000000000000000000000000\"}}]';"
|
|
" exit 0;; esac\n"
|
|
"[ -n \"$out\" ] && printf 0123456789 > \"$out\"\n"
|
|
"exit 0\n";
|
|
|
|
const char* kGoodOid =
|
|
"#!/bin/sh\n"
|
|
"out=''; url=''; prev=''\n"
|
|
"for a in \"$@\"; do\n"
|
|
" [ \"$prev\" = -o ] && out=\"$a\"\n"
|
|
" case \"$a\" in https://*) url=\"$a\";; esac\n"
|
|
" prev=\"$a\"\n"
|
|
"done\n"
|
|
"case \"$url\" in *api/models*)\n"
|
|
" oid=$(printf 0123456789 | sha256sum | cut -d' ' -f1)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"big.bin\",\"size\":10,\"lfs\":{\"oid\":\"%s\"}}]'"
|
|
" \"$oid\"; exit 0;; esac\n"
|
|
"[ -n \"$out\" ] && printf 0123456789 > \"$out\"\n"
|
|
"exit 0\n";
|
|
|
|
TEST(an_lfs_file_that_does_not_hash_to_its_oid_is_not_kept) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
if (!on_path("sha256sum")) SKIP("no sha256sum on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
const std::string fetch = "sh '" + hfget_beside_this_binary() +
|
|
"' radiance-test-owner/radiance-test-model '" + root.path +
|
|
"' >/dev/null 2>'" + root.path + "/err'";
|
|
{
|
|
FakeCurl curl(kBadOid);
|
|
CHECK(std::system(fetch.c_str()) != 0);
|
|
CHECK(!fs::exists(root.path + "/big.bin")); /* deleted, not left to be resumed */
|
|
CHECK(!fs::exists(root.path + "/.hfget-manifest"));
|
|
std::string err;
|
|
if (FILE* e = std::fopen((root.path + "/err").c_str(), "r")) {
|
|
char buf[256];
|
|
size_t n;
|
|
while ((n = std::fread(buf, 1, sizeof buf - 1, e)) > 0) { buf[n] = '\0'; err += buf; }
|
|
std::fclose(e);
|
|
}
|
|
CHECK(has(err, "hashes to"));
|
|
}
|
|
{
|
|
FakeCurl curl(kGoodOid);
|
|
CHECK_EQ(std::system(fetch.c_str()), 0);
|
|
CHECK(fs::exists(root.path + "/big.bin"));
|
|
CHECK_EQ(fs::file_size(root.path + "/big.bin"), 10u);
|
|
CHECK(fs::exists(root.path + "/.hfget-manifest")); /* the verified copy is certified */
|
|
}
|
|
}
|
|
|
|
/* --model-revision names the revision the fetch reads: the pinned ref is the one listed, and
|
|
* an unpinned fetch reads the repo's moving default branch -- which a deployment must be able
|
|
* to refuse outright rather than restart onto. */
|
|
const char* kPinnedOnly =
|
|
"#!/bin/sh\n"
|
|
"out=''; url=''; prev=''\n"
|
|
"for a in \"$@\"; do\n"
|
|
" [ \"$prev\" = -o ] && out=\"$a\"\n"
|
|
" case \"$a\" in https://*) url=\"$a\";; esac\n"
|
|
" prev=\"$a\"\n"
|
|
"done\n"
|
|
"case \"$url\" in *api/models*/tree/refs/pr/42*)\n"
|
|
" printf '[{\"type\":\"file\",\"path\":\"m.rad\",\"size\":10}]'; exit 0;; esac\n"
|
|
"case \"$url\" in *api/models*) exit 22;; esac\n"
|
|
"[ -n \"$out\" ] && printf 0123456789 > \"$out\"\n"
|
|
"exit 0\n";
|
|
|
|
TEST(the_pinned_revision_is_the_revision_fetched) {
|
|
NEED_ARTIFACT(hfget_beside_this_binary());
|
|
if (!on_path("jq")) SKIP("no jq on PATH, which hfget.sh needs");
|
|
TempDir root;
|
|
FakeCurl curl(kPinnedOnly);
|
|
const std::string repo = "radiance-test-owner/radiance-test-model";
|
|
auto resolve = [&](const char* rev, std::string* model) {
|
|
Config c;
|
|
c.model = repo;
|
|
c.download_dir = root.path;
|
|
if (rev) c.model_revision = rev;
|
|
bool ok = false;
|
|
stderr_of([&] { ok = resolve_hf_model(c); });
|
|
*model = c.model;
|
|
return ok;
|
|
};
|
|
std::string model;
|
|
CHECK(!resolve(nullptr, &model)); /* main: this hub has nothing there */
|
|
CHECK(resolve("refs/pr/42", &model));
|
|
CHECK_EQ(model, root.path + "/" + repo + "/m.rad");
|
|
}
|
|
|
|
/* With no --download-dir and neither XDG_CACHE_HOME nor HOME there is nowhere to fetch to, which
|
|
* is refused by name before anything runs. */
|
|
TEST(a_repo_id_with_nowhere_to_fetch_to_is_refused) {
|
|
const char* x = std::getenv("XDG_CACHE_HOME");
|
|
const char* h = std::getenv("HOME");
|
|
const std::string sx = x ? x : "", sh = h ? h : "";
|
|
unsetenv("XDG_CACHE_HOME");
|
|
unsetenv("HOME");
|
|
Config c;
|
|
c.model = "radiance-test-owner/radiance-test-model";
|
|
bool ok = true;
|
|
const std::string log = stderr_of([&] { ok = resolve_hf_model(c); });
|
|
CHECK(!ok);
|
|
CHECK(has(log, "--download-dir"));
|
|
CHECK_EQ(c.model, std::string("radiance-test-owner/radiance-test-model"));
|
|
if (x) setenv("XDG_CACHE_HOME", sx.c_str(), 1);
|
|
if (h) setenv("HOME", sh.c_str(), 1);
|
|
}
|
|
|
|
RAD_TEST_MAIN()
|