Archived
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
93 lines
3.2 KiB
C++
93 lines
3.2 KiB
C++
#ifndef RAD_YARN_H
|
|
#define RAD_YARN_H
|
|
|
|
/* Static YaRN coefficients. The architecture resolves the correction bounds from the original
|
|
* training length, never the deployment or table length. Kernels share the resolved coefficients
|
|
* so direct and table-backed RoPE cannot disagree.
|
|
*
|
|
* C++ gets RadYarn with a member frequency() (callable from HIP device code) and default member
|
|
* values; C gets the same four-float struct and rad_yarn_frequency(). The two definitions must
|
|
* compute the same frequencies; tests/abi_layout_test.cpp compares them. */
|
|
#include "rad_plugin.h"
|
|
|
|
#ifdef __cplusplus
|
|
#include <cmath>
|
|
|
|
#if defined(__HIPCC__)
|
|
#define RAD_YARN_HD __host__ __device__
|
|
#else
|
|
#define RAD_YARN_HD
|
|
#endif
|
|
|
|
struct RadYarn {
|
|
float factor = 0.0f; /* zero: YaRN off, frequency() returns `inv` unchanged */
|
|
float low = 0.0f;
|
|
float high = 0.0f;
|
|
float magnitude = 1.0f;
|
|
|
|
RAD_YARN_HD float frequency(float inv, int i) const {
|
|
if (factor == 0.0f) return inv;
|
|
const float width = high == low ? 0.001f : high - low;
|
|
const float ramp = fminf(1.0f, fmaxf(0.0f, ((float)i - low) / width));
|
|
/* Keep the blend order used by the reference YaRN implementation. */
|
|
const float mask = 1.0f - ramp;
|
|
return (inv / factor) * (1.0f - mask) + inv * mask;
|
|
}
|
|
};
|
|
|
|
inline RadYarn rad_yarn_args(const RadArgs* a) {
|
|
const float factor = (float)rad_args_getf_or(a, "yarn_factor", 0.0);
|
|
/* Disabled YaRN ignores every auxiliary coefficient on every backend. */
|
|
if (factor == 0.0f) return {};
|
|
return { factor,
|
|
(float)rad_args_getf_or(a, "yarn_low", 0.0),
|
|
(float)rad_args_getf_or(a, "yarn_high", 0.0),
|
|
(float)rad_args_getf_or(a, "yarn_magnitude", 1.0) };
|
|
}
|
|
|
|
inline bool rad_yarn_valid(const RadYarn& y) {
|
|
return std::isfinite(y.factor) && (y.factor == 0.0f ||
|
|
(y.factor >= 1.0f && std::isfinite(y.low) && std::isfinite(y.high) &&
|
|
y.high >= y.low && std::isfinite(y.magnitude) && y.magnitude > 0.0f));
|
|
}
|
|
|
|
#undef RAD_YARN_HD
|
|
|
|
#else /* C */
|
|
#include <math.h>
|
|
|
|
typedef struct RadYarn {
|
|
float factor; /* zero: YaRN off, rad_yarn_frequency() returns `inv` unchanged */
|
|
float low;
|
|
float high;
|
|
float magnitude; /* 1 when off */
|
|
} RadYarn;
|
|
|
|
static inline float rad_yarn_frequency(const RadYarn* y, float inv, int i) {
|
|
float width, ramp, mask;
|
|
if (y->factor == 0.0f) return inv;
|
|
width = y->high == y->low ? 0.001f : y->high - y->low;
|
|
ramp = fminf(1.0f, fmaxf(0.0f, ((float)i - y->low) / width));
|
|
mask = 1.0f - ramp;
|
|
return (inv / y->factor) * (1.0f - mask) + inv * mask;
|
|
}
|
|
|
|
static inline RadYarn rad_yarn_args(const RadArgs* a) {
|
|
RadYarn y = { 0.0f, 0.0f, 0.0f, 1.0f };
|
|
y.factor = (float)rad_args_getf_or(a, "yarn_factor", 0.0);
|
|
if (y.factor == 0.0f) return y;
|
|
y.low = (float)rad_args_getf_or(a, "yarn_low", 0.0);
|
|
y.high = (float)rad_args_getf_or(a, "yarn_high", 0.0);
|
|
y.magnitude = (float)rad_args_getf_or(a, "yarn_magnitude", 1.0);
|
|
return y;
|
|
}
|
|
|
|
static inline int rad_yarn_valid(const RadYarn* y) {
|
|
return isfinite(y->factor) && (y->factor == 0.0f ||
|
|
(y->factor >= 1.0f && isfinite(y->low) && isfinite(y->high) && y->high >= y->low &&
|
|
isfinite(y->magnitude) && y->magnitude > 0.0f));
|
|
}
|
|
#endif
|
|
|
|
#endif
|