bundled_models.cpp¶
src/config/bundled_models.cpp
@file bundled_models.cpp @brief BundledModels registry implementation.
Owners: @tvanfossen
auto_discover_and_load
std::string entropic::config::BundledModels::auto_discover_and_load()
Auto-discover and load bundled_models.yaml.
src/config/bundled_models.cpp:269
Called by do_configure_dir, do_configure_from_file, do_configure_json, run_download
Calls load, share_dir_from_library
Source · 35 lines
std::string BundledModels::auto_discover_and_load() {
// Discovery order mirrors data_dir.cpp::resolve_data_dir so the
// registry is found the same way as prompts/grammars/schemas:
// 1. ENTROPIC_DATA_DIR env (explicit operator override)
// 2. binary-relative via dladdr (portable across install prefixes)
// 3-5. compile-time install path, source tree, CWD (dev/build-host)
// Pre-v2.3.6 this list was only 3-5 — purely compile-time/CWD — so
// a relocated install (any machine that isn't the build host, incl.
// container-staged release binaries) silently loaded zero models.
std::vector<std::filesystem::path> candidates;
if (const char* env = std::getenv("ENTROPIC_DATA_DIR"); env && *env) {
candidates.emplace_back(std::filesystem::path(env) / "bundled_models.yaml");
}
if (auto from_lib = share_dir_from_library(); !from_lib.empty()) {
candidates.emplace_back(from_lib / "bundled_models.yaml");
}
candidates.emplace_back(
std::filesystem::path(CONFIG_ENTROPIC_DATA_DIR) / "bundled_models.yaml");
candidates.emplace_back(
std::filesystem::path(CONFIG_ENTROPIC_SOURCE_DATA_DIR) / "bundled_models.yaml");
candidates.emplace_back("data/bundled_models.yaml");
for (const auto& path : candidates) {
if (std::filesystem::is_regular_file(path)) {
auto err = load(path);
if (err.empty()) {
s_log->info("pre-loaded {} bundled model(s) from {}",
entries_.size(), path.string());
return "";
}
s_log->warn("bundled models load failed: {} — {}", path.string(), err);
}
}
return "bundled_models.yaml not found in default paths";
}Activity · 16 steps
Requirements
find_by
std::string entropic::config::BundledModels::find_by(const std::string &family, const std::string &size_label, const std::string &quant) const
Look up a registry key by (family, size, quant) (gh#62).
src/config/bundled_models.cpp:162
Source · 14 lines
std::string BundledModels::find_by(
const std::string& family,
const std::string& size_label,
const std::string& quant) const
{
for (const auto& [key, entry] : entries_) {
if (entry.family == family
&& entry.size_label == size_label
&& entry.quant == quant) {
return key;
}
}
return "";
}Activity · 4 steps
Requirements
load
std::string entropic::config::BundledModels::load(const std::filesystem::path &path)
Load registry from YAML file.
src/config/bundled_models.cpp:95
Called by SCENARIO, SCENARIO, auto_discover_and_load, layered, load_registry, load_test_registry, parse
Calls parse_bundled_entry, parse_yaml, read_file
Source · 26 lines
std::string BundledModels::load(const std::filesystem::path& path)
{
auto content = read_file(path);
if (content.empty()) {
return "cannot read " + path.string();
}
ryml::Tree tree;
std::string err = parse_yaml(path.string(), content, tree); // gh#211
ryml::ConstNodeRef root;
if (err.empty()) { root = tree.rootref(); }
if (err.empty() && !root.is_map()) {
err = "bundled_models.yaml root is not a mapping";
}
if (!err.empty()) { return err; }
for (auto child : root) {
BundledModelEntry entry;
err = parse_bundled_entry(child, entry);
if (!err.empty()) { break; }
s_log->info("Registered bundled model: {} -> {} ({:.1f} GB)",
entry.key, entry.name, entry.size_gb);
entries_[entry.key] = std::move(entry);
}
return err;
}Activity · 20 steps
Requirements
parse_bundled_entry
static std::string entropic::config::parse_bundled_entry(ryml::ConstNodeRef child, BundledModelEntry &entry)
Parse one bundled-model YAML entry into entry .
src/config/bundled_models.cpp:66
Source · 21 lines
static std::string parse_bundled_entry(ryml::ConstNodeRef child,
BundledModelEntry& entry)
{
entry.key = to_string(child.key());
extract(child, "name", entry.name);
extract(child, "url", entry.url);
extract(child, "size_gb", entry.size_gb);
extract(child, "adapter", entry.adapter);
extract(child, "description", entry.description);
extract(child, "mmproj_key", entry.mmproj_key);
// gh#62 (v2.3.0): optional structured selectors. Entries that
// don't declare them stay queryable by flat key only.
extract(child, "provider", entry.provider);
extract(child, "family", entry.family);
extract(child, "size_label", entry.size_label);
extract(child, "quant", entry.quant);
if (entry.name.empty()) {
return "bundled model '" + entry.key + "' missing 'name'";
}
return "";
}Activity · 14 steps
Requirements
resolve
std::filesystem::path entropic::config::BundledModels::resolve(const std::string &value) const
Resolve a model reference to a filesystem path.
src/config/bundled_models.cpp:200
Called by SCENARIO, describe_run, init_orchestrator_for_v219_family, parse_model_config, repoint_mmproj, reserve_forced_partial, resolve_model_path, run_four_arm_bench, use_small_default_model
Tested by 1 tests
run_prefill_residency_bench
Calls expand_home
Source · 41 lines
std::filesystem::path BundledModels::resolve(const std::string& value) const
{
auto it = entries_.find(value);
if (it == entries_.end()) {
return expand_home(std::filesystem::path(value));
}
const auto filename = it->second.name + ".gguf";
std::filesystem::path result;
const char* reason = nullptr;
// Priority 1: explicit operator override via env var always wins.
// Deliberately does NOT check existence — the user may be pointing
// at a download destination that hasn't been populated yet.
if (const char* env = std::getenv("ENTROPIC_MODEL_DIR"); env && *env) {
result = std::filesystem::path(env) / filename;
reason = "ENTROPIC_MODEL_DIR";
} else {
// Priority 2-3: user home, then system. First existing file wins;
// if neither exists, home_path is returned so error messages
// point at the most-likely-intended location.
const auto home_path =
expand_home("~") / ".entropic" / "models" / filename;
const auto sys_path =
std::filesystem::path("/opt/entropic/models") / filename;
if (std::filesystem::is_regular_file(sys_path)
&& !std::filesystem::is_regular_file(home_path)) {
result = sys_path;
reason = "/opt/entropic/models";
} else {
result = home_path;
reason = std::filesystem::is_regular_file(home_path)
? "~/.entropic/models"
: "fallback (file not found)";
}
}
s_log->info("Model '{}' resolved to {} ({})",
value, result.string(), reason);
return result;
}