diff --git a/arch/common/rad_arch.h b/arch/common/rad_arch.h index 6d68e746..5073ea70 100644 --- a/arch/common/rad_arch.h +++ b/arch/common/rad_arch.h @@ -17,6 +17,7 @@ #include "rad_yarn.h" #include "rad_abi_layout.h" +#include #include #include #include @@ -123,6 +124,36 @@ inline const char* calib_dir() { return d && *d ? d : nullptr; } +/* Whether layer `layer` taps (RADIANCE_CALIB_LAYERS: comma-separated layers and "lo-hi" ranges; + * unset, every layer). A model whose per-expert Hessians do not fit the host at once (Nemotron-3.5 + * Bolt's are 169 GiB) calibrates in several runs over disjoint ranges; each run writes only its + * layers' files, so the runs share one directory. */ +inline bool calib_layer_on(int layer) { + static const std::vector> ranges = [] { + std::vector> r; + const char* s = std::getenv("RADIANCE_CALIB_LAYERS"); + while (s && *s) { + char* e = nullptr; + const long lo = std::strtol(s, &e, 10); + if (e == s) break; + long hi = lo; + if (*e == '-') { + const char* h = e + 1; + hi = std::strtol(h, &e, 10); + if (e == h) break; + } + r.emplace_back((int)lo, (int)hi); + s = *e == ',' ? e + 1 : e; + if (*s && *s != ',' && !std::isdigit((unsigned char)*s)) break; + } + return r; + }(); + if (!std::getenv("RADIANCE_CALIB_LAYERS")) return true; + for (const auto& r : ranges) + if (layer >= r.first && layer <= r.second) return true; + return false; +} + /* Token count at which the tap dumps and switches itself off (RADIANCE_CALIB_TOKENS, default * 65536). Whether the tap runs at all is calib_dir()'s decision. */ inline long long calib_target() { diff --git a/arch/common/rad_block_moe_fp8.h b/arch/common/rad_block_moe_fp8.h index d151c029..b2d5cefa 100644 --- a/arch/common/rad_block_moe_fp8.h +++ b/arch/common/rad_block_moe_fp8.h @@ -1833,6 +1833,9 @@ inline void MoeFP8::pass(RadCtx* c_, int64_t T, int64_t r0, int64_t rows, bool o (!calib_dne_failed && calib_dne.write(gram_dn_stem, c.expert_base, gram_domain, rad_rank(c_))); + /* Written: the host sums are done with (a layer's can be gigabytes). */ + calib_dne.acc = {}; + calib_dne.rows = {}; calib_done = true; if (layer == 0) std::fprintf(stderr, "radiance: calibration wrote layer Hessians after %lld "