This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/tests/hf_model_test.cpp
T
Deadcode 89cee7ce41 radiance 1.3.0
- #47: llama-server's request fields, routes and sampler order, and /props (with baKon's model
  entry: max_model_len, root and capabilities on /v1/models, and /v1/models/:id)
- new APIs: Anthropic's Messages API (/v1/messages), OpenAI's Responses API (/v1/responses),
  llama-server's /completion and /infill, logprobs (OpenAI's logprobs and top_logprobs, up to
  20; llama-server's n_probs), OpenAI's legacy `functions`, and X-Api-Key beside the bearer key
- #4: --model takes a Hugging Face repo id (owner/name), fetched before startup into
  ~/.cache/radiance/hf or --download-dir and checked for changes at every start (redxherring)
- #46: --tp 3 --tp-wire wht6 serves -- a three-rank two-shot all-reduce with uneven shards and
  the tiered-int8 wire over it (baKon); scripts/cardclock.py names what holds each card's clock
  under load (baKon)
- CPU-only serving works again; --kernels names the kernel libraries to load; a model the
  loaded libraries cannot fully serve refuses at startup instead of failing its first request;
  --vram-kv-mib and --vram-weights-mib are gone (the split is automatic)
- --embedding-placement ram is the default, and `auto` is gone
- #40: Swift 1.5 recipes; rad-convert reads which shard holds a tensor from the index
- #53: the pinned host pool gets huge pages where shmem THP is off; #57: a crash on video with
  an odd frame width is fixed
2026-10-08 18:22:08 +02:00

125 lines
4.4 KiB
C++

/* hf_model_test.cpp -- a --model that names a Hugging Face repo (core/hf_model.h).
*
* Two questions, both answered before anything is fetched, and both wrong in a way that 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 the hub's model repos hold one container beside a README, a recipe and a
* licence; a checkpoint repo holds none and is served as the directory
*
* No network: the fetch itself is scripts/hfget.sh, which this does not run.
*/
#include "rad_test.h"
#include "hf_model.h"
#include <cstdio>
#include <cstdlib>
#include <filesystem>
#include <string>
#include <unistd.h>
using namespace rad;
namespace fs = std::filesystem;
namespace {
/* A scratch directory of its own, removed with everything in it. */
struct TempDir {
std::string path;
TempDir() {
char t[] = "/tmp/hf_model_test.XXXXXX";
path = mkdtemp(t) ? t : "";
}
~TempDir() {
std::error_code ec;
if (!path.empty()) fs::remove_all(path, ec);
}
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;
CHECK(!t.path.empty());
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);
}
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);
}
RAD_TEST_MAIN()