Archived
nemotron 3.5 implementation
This commit is contained in:
1 parent
33108e488b
commit
94c90b17ad
59 files changed
+6046
-76
No files matched your search
@@ -807,6 +807,34 @@ static int rope_ladder(const RadArgs* a, int64_t rot, int64_t head_dim, int64_t*
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* Ministral 3's query multiplier, applied after rotary and rounded to the activation dtype
|
||||
* before the product. Only the supplied query slice is changed; keys and values stay intact. */
|
||||
int ref_position_scale(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *x = &a->t[0], *pos = &a->t[1];
|
||||
// M in the resolved geometry is a capacity band; issued views carry the active rows.
|
||||
const int64_t M = x->rank == 2 ? x->shape[0] : 0;
|
||||
const int64_t n = p_int(a, "n", 0), orig = p_int(a, "original", 0);
|
||||
const float beta = p_f32(a, "beta", -1);
|
||||
if (M <= 0 || M > p_int(a, "M", 0) || n <= 0 || orig <= 0 || !std::isfinite(beta) || beta < 0 ||
|
||||
x->rank != 2 || x->shape[0] < M || x->shape[1] != n || pos->rank != 1 || numel(pos) < M)
|
||||
return RAD_E_SHAPE;
|
||||
if (pos->dtype != RAD_I32 || (x->dtype != RAD_BF16 && x->dtype != RAD_F32)) return RAD_E_DTYPE;
|
||||
/* Validate all positions before writing: an invalid batch must not leave a partial result. */
|
||||
for (int64_t r = 0; r < M; ++r)
|
||||
if (ld_int(pos->dtype, pos->data, offlin(pos, r)) < 0) return RAD_E_INVAL;
|
||||
REF_PAR_FOR(M * n)
|
||||
for (int64_t r = 0; r < M; ++r) {
|
||||
const int64_t p = ld_int(pos->dtype, pos->data, offlin(pos, r));
|
||||
const float scale = round_dt(x->dtype, 1.0f + beta * std::log(1.0f + (float)(p / orig)));
|
||||
for (int64_t j = 0; j < n; ++j) {
|
||||
const int64_t at = rowoff(x, r, n) + j * laststride(x);
|
||||
stt(x, at, ldt(x, at) * scale);
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_rope(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *qkv = &a->t[0], *pos = &a->t[1];
|
||||
|
||||
@@ -159,6 +159,11 @@ int ref_kv_store (const RadArgs*, RadStream);
|
||||
/* the store of a streamed group: the host mirror always, the ring slot when the block is resident */
|
||||
int ref_kv_store_streamed (const RadArgs*, RadStream);
|
||||
int ref_rope (const RadArgs*, RadStream);
|
||||
int ref_position_scale (const RadArgs*, RadStream);
|
||||
int ref_embed_attn (const RadArgs*, RadStream);
|
||||
int ref_ministral_rope (const RadArgs*, RadStream);
|
||||
int ref_pixtral_rope (const RadArgs*, RadStream);
|
||||
int ref_pixtral_merge (const RadArgs*, RadStream);
|
||||
int ref_rope_table (const RadArgs*, RadStream);
|
||||
int ref_qk_norm_rope (const RadArgs*, RadStream);
|
||||
/* image generation (ref_gen.cpp) */
|
||||
@@ -423,6 +428,11 @@ REF_SHAPE_FN(ref_sam_attn);
|
||||
REF_SHAPE_FN(ref_kv_store);
|
||||
REF_SHAPE_FN(ref_kv_store_streamed);
|
||||
REF_SHAPE_FN(ref_rope);
|
||||
REF_SHAPE_FN(ref_position_scale);
|
||||
REF_SHAPE_FN(ref_embed_attn);
|
||||
REF_SHAPE_FN(ref_ministral_rope);
|
||||
REF_SHAPE_FN(ref_pixtral_rope);
|
||||
REF_SHAPE_FN(ref_pixtral_merge);
|
||||
REF_SHAPE_FN(ref_rope_table);
|
||||
REF_SHAPE_FN(ref_qk_norm_rope);
|
||||
REF_SHAPE_FN(ref_ln_mod);
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
/* Nemotron's text/vision rotary, patch merger and materialized BF16 attention.
|
||||
* Separate ops preserve existing rotary, attention and merger contracts. */
|
||||
#include "ref_common.h"
|
||||
#include "ref_ops.h"
|
||||
|
||||
#include "rad_yarn.h"
|
||||
|
||||
using namespace ref;
|
||||
|
||||
int ref_pixtral_rope(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *x = &a->t[0], *rc = &a->t[1];
|
||||
// The issue's row views can be smaller than the resolved M capacity band.
|
||||
const int64_t M = x->rank == 2 ? x->shape[0] : 0;
|
||||
const int64_t D = p_int(a, "head_dim", 0), H = p_int(a, "n_head", 0);
|
||||
const float theta = p_f32(a, "theta", 0);
|
||||
if (M <= 0 || M > p_int(a, "M", 0) || D <= 0 || D % 4 || H <= 0 || !(theta > 0) ||
|
||||
!std::isfinite(theta) || x->rank != 2 || x->shape[0] < M || x->shape[1] != 3 * H * D ||
|
||||
rc->rank != 2 || rc->shape[0] != 2 || rc->shape[1] != M)
|
||||
return RAD_E_SHAPE;
|
||||
if (rc->dtype != RAD_I32 || (x->dtype != RAD_BF16 && x->dtype != RAD_F32)) return RAD_E_DTYPE;
|
||||
for (int64_t r = 0; r < 2; ++r)
|
||||
for (int64_t p = 0; p < M; ++p)
|
||||
if (ld_int(rc->dtype, rc->data, r * rc->stride[0] + p * rc->stride[1]) < 0)
|
||||
return RAD_E_INVAL;
|
||||
REF_PAR_FOR(M * H * D)
|
||||
for (int64_t p = 0; p < M; ++p) {
|
||||
for (int64_t i = 0; i < D / 2; ++i) {
|
||||
const int64_t axis = i / (D / 4), j = i % (D / 4);
|
||||
const float pos =
|
||||
(float)ld_int(rc->dtype, rc->data, axis * rc->stride[0] + p * rc->stride[1]);
|
||||
const float inv = 1.0f / ref_pow(theta, (float)(4 * j + 2 * axis) / D);
|
||||
const float angle = pos * inv;
|
||||
const float c = round_dt(x->dtype, ref_cos(angle)),
|
||||
s = round_dt(x->dtype, ref_sin(angle));
|
||||
for (int64_t h = 0; h < 2 * H; ++h) {
|
||||
const int64_t u = rowoff(x, p, 3 * H * D) + (h * D + i) * laststride(x);
|
||||
const int64_t v = u + (D / 2) * laststride(x);
|
||||
const float a0 = ldt(x, u), b0 = ldt(x, v);
|
||||
/* Transformers narrows cos/sin and each product before adding BF16 tensors. */
|
||||
stt(x, u, round_dt(x->dtype, a0 * c) - round_dt(x->dtype, b0 * s));
|
||||
stt(x, v, round_dt(x->dtype, b0 * c) + round_dt(x->dtype, a0 * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_pixtral_merge(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 3)) return RAD_E_INVAL;
|
||||
const RadTensor *x = &a->t[0], *rc = &a->t[1], *y = &a->t[2];
|
||||
const int64_t M = x->rank == 2 ? x->shape[0] : 0;
|
||||
const int64_t N = p_int(a, "n", 0), K = p_int(a, "merge", 0);
|
||||
if (M <= 0 || M > p_int(a, "M", 0) || N <= 0 || K <= 0 || K > M || M / K < K || M % (K * K) ||
|
||||
x->rank != 2 || x->shape[0] != M || x->shape[1] != N || rc->rank != 2 ||
|
||||
rc->shape[0] != 4 || rc->shape[1] != M || y->rank != 2 || y->shape[0] != M / (K * K) ||
|
||||
y->shape[1] != N * K * K)
|
||||
return RAD_E_SHAPE;
|
||||
if (rc->dtype != RAD_I32 || x->dtype != y->dtype ||
|
||||
(x->dtype != RAD_BF16 && x->dtype != RAD_F32))
|
||||
return RAD_E_DTYPE;
|
||||
const auto coord = [&](int axis, int64_t p) {
|
||||
return ld_int(rc->dtype, rc->data, axis * rc->stride[0] + p * rc->stride[1]);
|
||||
};
|
||||
/* Verify full raster grids before any write, including variable image widths. The grid at
|
||||
* each image's first patch defines its boundary; no image is merged with the next one. */
|
||||
for (int64_t p = 0; p < M;) {
|
||||
const int64_t h = coord(2, p), w = coord(3, p);
|
||||
if (h <= 0 || w <= 0 || h % K || w % K || h > (M - p) / w) return RAD_E_INVAL;
|
||||
for (int64_t j = 0; j < h * w; ++j)
|
||||
if (coord(0, p + j) != j / w || coord(1, p + j) != j % w || coord(2, p + j) != h ||
|
||||
coord(3, p + j) != w)
|
||||
return RAD_E_INVAL;
|
||||
p += h * w;
|
||||
}
|
||||
for (int64_t p = 0; p < M;) {
|
||||
const int64_t h = coord(2, p), w = coord(3, p);
|
||||
for (int64_t r = 0; r < h / K; ++r)
|
||||
for (int64_t c = 0; c < w / K; ++c) {
|
||||
const int64_t dst = p / (K * K) + r * (w / K) + c;
|
||||
for (int64_t n = 0; n < N; ++n)
|
||||
for (int64_t dy = 0; dy < K; ++dy)
|
||||
for (int64_t dx = 0; dx < K; ++dx) {
|
||||
const int64_t src = p + (r * K + dy) * w + c * K + dx;
|
||||
const int64_t col = (n * K + dy) * K + dx;
|
||||
stt(y, rowoff(y, dst, N * K * K) + col * laststride(y),
|
||||
ldt(x, rowoff(x, src, N) + n * laststride(x)));
|
||||
}
|
||||
}
|
||||
p += h * w;
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int ref_ministral_rope(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 2)) return RAD_E_INVAL;
|
||||
const RadTensor *x = &a->t[0], *pos = &a->t[1];
|
||||
const int64_t M = x->rank == 2 ? x->shape[0] : 0;
|
||||
const int64_t D = p_int(a, "head_dim", 0), H = p_int(a, "n_head", 0),
|
||||
K = p_int(a, "n_head_kv", 0);
|
||||
const float theta = p_f32(a, "theta", 0);
|
||||
const RadYarn yarn = rad_yarn_args(a);
|
||||
if (M <= 0 || M > p_int(a, "M", 0) || D <= 0 || D > 2048 || D % 2 || H <= 0 || H > 1024 ||
|
||||
K <= 0 || K > H || H % K || x->shape[1] != (H + 2 * K) * D || pos->rank != 1 ||
|
||||
numel(pos) != M || !(theta > 0) || !std::isfinite(theta) || !rad_yarn_valid(yarn))
|
||||
return RAD_E_SHAPE;
|
||||
if (pos->dtype != RAD_I32 || (x->dtype != RAD_BF16 && x->dtype != RAD_F32)) return RAD_E_DTYPE;
|
||||
for (int64_t p = 0; p < M; ++p)
|
||||
if (ld_int(pos->dtype, pos->data, offlin(pos, p)) < 0) return RAD_E_INVAL;
|
||||
float freq[1024];
|
||||
for (int64_t i = 0; i < D / 2; ++i)
|
||||
freq[i] = yarn.frequency(1.0f / std::pow(theta, (float)(2 * i) / (float)D), (int)i);
|
||||
REF_PAR_FOR(M * (H + K) * D)
|
||||
for (int64_t p = 0; p < M; ++p) {
|
||||
const float position = (float)(ld_int(pos->dtype, pos->data, offlin(pos, p)));
|
||||
for (int64_t i = 0; i < D / 2; ++i) {
|
||||
const float angle = position * freq[i];
|
||||
const float c = round_dt(x->dtype, std::cos(angle) * yarn.magnitude);
|
||||
const float s = round_dt(x->dtype, std::sin(angle) * yarn.magnitude);
|
||||
for (int64_t h = 0; h < H + K; ++h) {
|
||||
const int64_t u = rowoff(x, p, (H + 2 * K) * D) + (h * D + i) * laststride(x);
|
||||
const int64_t v = u + (D / 2) * laststride(x);
|
||||
const float a0 = ldt(x, u), b0 = ldt(x, v);
|
||||
stt(x, u, round_dt(x->dtype, a0 * c) - round_dt(x->dtype, b0 * s));
|
||||
stt(x, v, round_dt(x->dtype, b0 * c) + round_dt(x->dtype, a0 * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
/* The eager BF16 attention expression materializes QK, scaled logits and probabilities.
|
||||
* Keep it separate from attn_dense's existing fused arithmetic. Only whole, noncausal segments
|
||||
* are served. Stack storage is bounded by the model's 32768-token limit. */
|
||||
int ref_embed_attn(const RadArgs* a, RadStream) {
|
||||
if (!have(a, 5)) return RAD_E_INVAL;
|
||||
const RadTensor *q = &a->t[0], *k = &a->t[1], *v = &a->t[2], *cu = &a->t[3], *out = &a->t[4];
|
||||
const int64_t M = q->rank == 2 ? q->shape[0] : 0;
|
||||
const int64_t D = p_int(a, "head_dim", 0), G = p_int(a, "gqa", 1);
|
||||
if (M <= 0 || M > p_int(a, "M", 0) || D <= 0 || D > 2048 || G <= 0 || q->shape[1] <= 0 ||
|
||||
q->shape[1] % D || k->rank != 2 || v->rank != 2 || out->rank != 2 || cu->rank != 1 ||
|
||||
numel(cu) < 2 || k->shape[0] != M || v->shape[0] != M || out->shape[0] != M)
|
||||
return RAD_E_SHAPE;
|
||||
const int64_t H = q->shape[1] / D, S = numel(cu) - 1;
|
||||
if (H % G || k->shape[1] != H / G * D || v->shape[1] != H / G * D || out->shape[1] != H * D)
|
||||
return RAD_E_SHAPE;
|
||||
if (p_int(a, "causal", 0) != 0) return RAD_E_UNSUPPORTED;
|
||||
if ((q->dtype != RAD_BF16 && q->dtype != RAD_F32) || k->dtype != q->dtype ||
|
||||
v->dtype != q->dtype || out->dtype != q->dtype || cu->dtype != RAD_I32)
|
||||
return RAD_E_DTYPE;
|
||||
auto boundary = [&](int64_t s) { return ld_int(cu->dtype, cu->data, offlin(cu, s)); };
|
||||
if (boundary(0) != 0 || boundary(S) != M) return RAD_E_INVAL;
|
||||
for (int64_t s = 0; s < S; ++s)
|
||||
if (boundary(s) >= boundary(s + 1) || boundary(s + 1) - boundary(s) > 32768)
|
||||
return RAD_E_INVAL;
|
||||
const float scale = p_f32(a, "scale", 1.0f / std::sqrt((float)D));
|
||||
if (!std::isfinite(scale) || !(scale > 0)) return RAD_E_INVAL;
|
||||
REF_PAR_FOR(M * H * D)
|
||||
for (int64_t sh = 0; sh < S * H; ++sh) {
|
||||
const int64_t s = sh / H, h = sh % H, kh = h / G;
|
||||
const int64_t begin = boundary(s), end = boundary(s + 1);
|
||||
float scores[32768], accum[2048];
|
||||
for (int64_t i = begin; i < end; ++i) {
|
||||
const int64_t qb = rowoff(q, i, H * D) + h * D * laststride(q);
|
||||
float maximum = -INFINITY;
|
||||
for (int64_t j = begin; j < end; ++j) {
|
||||
const int64_t kb = rowoff(k, j, H / G * D) + kh * D * laststride(k);
|
||||
float dot = 0;
|
||||
for (int64_t d = 0; d < D; ++d)
|
||||
dot += ldt(q, qb + d * laststride(q)) * ldt(k, kb + d * laststride(k));
|
||||
const float score = round_dt(q->dtype, round_dt(q->dtype, dot) * scale);
|
||||
scores[j - begin] = score;
|
||||
maximum = std::max(maximum, score);
|
||||
}
|
||||
float sum = 0;
|
||||
for (int64_t j = begin; j < end; ++j) {
|
||||
scores[j - begin] = std::exp(scores[j - begin] - maximum);
|
||||
sum += scores[j - begin];
|
||||
}
|
||||
std::fill_n(accum, D, 0.0f);
|
||||
for (int64_t j = begin; j < end; ++j) {
|
||||
const float probability = round_dt(q->dtype, scores[j - begin] / sum);
|
||||
const int64_t vb = rowoff(v, j, H / G * D) + kh * D * laststride(v);
|
||||
for (int64_t d = 0; d < D; ++d)
|
||||
accum[d] += probability * ldt(v, vb + d * laststride(v));
|
||||
}
|
||||
const int64_t ob = rowoff(out, i, H * D) + h * D * laststride(out);
|
||||
for (int64_t d = 0; d < D; ++d)
|
||||
stt(out, ob + d * laststride(out), accum[d]);
|
||||
}
|
||||
}
|
||||
return RAD_OK;
|
||||
}
|
||||
@@ -435,6 +435,23 @@ static const RadParamSpec pRope[] = { P_INT("M"), P_INT("head_dim"), P_INT("n_he
|
||||
P_F64O("llama3_orig") };
|
||||
static const RadOperandSpec oRope[] = { INOUT("qkv"), OPD("positions") };
|
||||
|
||||
static const RadParamSpec pPositionScale[] = { P_INT("M"), P_INT("n"), P_INT("original"),
|
||||
P_F64("beta"), P_STR("dtype") };
|
||||
static const RadOperandSpec oPositionScale[] = { INOUT("x"), OPD("positions") };
|
||||
|
||||
static const RadParamSpec pEmbedAttn[] = { P_INT("M"), P_INT("head_dim"), P_INT("gqa"),
|
||||
P_INT("causal"), P_INTO("max_seqlen"), P_STR("dtype"), P_F64O("scale") };
|
||||
static const RadOperandSpec oEmbedAttn[] = { OPD("q"), OPD("k"), OPD("v"), OPD("cu_seqlens"), OUT("out") };
|
||||
static const RadParamSpec pMinistralRope[] = { P_INT("M"), P_INT("head_dim"), P_INT("n_head"),
|
||||
P_INT("n_head_kv"), P_F64("theta"), P_STR("dtype"), P_F64O("yarn_factor"),
|
||||
P_F64O("yarn_low"), P_F64O("yarn_high"), P_F64O("yarn_magnitude") };
|
||||
static const RadOperandSpec oMinistralRope[] = { INOUT("qkv"), OPD("pos") };
|
||||
static const RadParamSpec pPixtralRope[] = { P_INT("M"), P_INT("head_dim"), P_INT("n_head"),
|
||||
P_F64("theta"), P_STR("dtype") };
|
||||
static const RadOperandSpec oPixtralRope[] = { INOUT("qkv"), OPD("coord") };
|
||||
static const RadParamSpec pPixtralMerge[] = { P_INT("M"), P_INT("n"), P_INT("merge"), P_STR("dtype") };
|
||||
static const RadOperandSpec oPixtralMerge[] = { OPD("x"), OPD("coord"), OUT("y") };
|
||||
|
||||
/* The cos/sin plane a fused prologue reads instead of theta, at each position's own row of a
|
||||
* [max_ctx, rot] table. `rot`, `theta` and `scale` are spelled as on `rope`, which must compute the
|
||||
* same angles. */
|
||||
@@ -1457,6 +1474,17 @@ static const RadOpSchema kSchemas[] = {
|
||||
"cos/sin for the positions a step names, at each position's own row of a [max_ctx, rot] plane: "
|
||||
"rot values a row, cos for the first half and sin for the second. The angles are `rope`'s "
|
||||
"exactly. A row no position names is not written; a negative position writes nothing." },
|
||||
{ "embed_attn", ARR(pEmbedAttn), ARR(oEmbedAttn),
|
||||
"Whole noncausal segments with QK, scaled scores and probabilities rounded to activation dtype." },
|
||||
{ "ministral_rope", ARR(pMinistralRope), ARR(oMinistralRope),
|
||||
"Ministral NeoX rotary with BF16 cos/sin and separately rounded products; V is unchanged." },
|
||||
{ "pixtral_rope", ARR(pPixtralRope), ARR(oPixtralRope),
|
||||
"Pixtral axial rotary with interleaved height/width frequencies and BF16 product rounding." },
|
||||
{ "pixtral_merge", ARR(pPixtralMerge), ARR(oPixtralMerge),
|
||||
"Pack full raster patch grids into channel-major spatial merge blocks, without mixing images." },
|
||||
{ "position_scale", ARR(pPositionScale), ARR(oPositionScale),
|
||||
"Scale query row p by 1 + beta * log(1 + floor(position[p] / original)), rounding the scale "
|
||||
"to x's dtype before multiplication. Positions are nonnegative i32." },
|
||||
{ "qsa_block_key", ARR(pQsaBlockKey), ARR(oQsaBlockKey),
|
||||
"QSA's compressed key, one vector per `ratio` rows of k: the block's mean accumulated in f32 and "
|
||||
"rounded to k's dtype, RMS-normed with gain (wadd + w), then NeoX-rotated over `rotary_dim` at "
|
||||
@@ -2380,6 +2408,11 @@ ROW("ref_kv_store_streamed", "kv_store_streamed", "attn",
|
||||
"scatter k and v into the host mirror always and into the resident ring slot", DT_ANY,
|
||||
nullptr, 0, nullptr, nullptr, ref_kv_store_streamed, nullptr),
|
||||
SIMPLE("ref_rope", "rope", "attn", "rotary embedding in place", DT_FLOAT, ref_rope),
|
||||
SIMPLE("ref_embed_attn", "embed_attn", "attn", "BF16 materialized encoder attention", "bf16/f32, i32 cu", ref_embed_attn),
|
||||
SIMPLE("ref_ministral_rope", "ministral_rope", "attn", "Ministral BF16 rotary", "bf16/f32 inout, i32 positions", ref_ministral_rope),
|
||||
SIMPLE("ref_pixtral_rope", "pixtral_rope", "attn", "Pixtral interleaved axial rotary", "bf16/f32 inout, i32 coordinates", ref_pixtral_rope),
|
||||
SIMPLE("ref_pixtral_merge", "pixtral_merge", "vision", "channel-major patch merger packing", "bf16/f32, i32 coordinates", ref_pixtral_merge),
|
||||
SIMPLE("ref_position_scale", "position_scale", "attn", "Ministral position-dependent query scale", "bf16/f32 inout, i32 positions", ref_position_scale),
|
||||
SIMPLE("ref_qk_norm_rope", "qk_norm_rope", "attn", "per-head QK norm then rotary embedding",
|
||||
DT_FLOAT, ref_qk_norm_rope),
|
||||
|
||||
|
||||
@@ -534,6 +534,52 @@ int ref_act_mul_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return binary_shape(p, n_p, operand, "act_mul", out);
|
||||
}
|
||||
|
||||
int ref_position_scale_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
if (M <= 0 || n <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, n});
|
||||
o.t_idx({M}, 32768, -1, 0);
|
||||
return o.finish("position_scale", operand, out);
|
||||
}
|
||||
|
||||
int ref_embed_attn_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0);
|
||||
const int64_t G = gi(p, n_p, "gqa", 1), S = n_seq_of(p, n_p);
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, G * D});
|
||||
o.t(act_dt(p, n_p), {M, D});
|
||||
o.t(act_dt(p, n_p), {M, D});
|
||||
o.t_idx({S + 1}, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU);
|
||||
o.t(act_dt(p, n_p), {M, G * D});
|
||||
return o.finish("embed_attn", operand, out);
|
||||
}
|
||||
|
||||
int ref_ministral_rope_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0);
|
||||
const int64_t H = gi(p, n_p, "n_head", 0), K = gi(p, n_p, "n_head_kv", 0);
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, (H + 2 * K) * D});
|
||||
o.t_idx({M}, 32768, -1, 0);
|
||||
return o.finish("ministral_rope", operand, out);
|
||||
}
|
||||
|
||||
int ref_pixtral_rope_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0),
|
||||
H = gi(p, n_p, "n_head", 0);
|
||||
if (M <= 0 || D <= 0 || D % 4 || H <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, 3 * H * D});
|
||||
o.t_idx({2, M}, 80, -1, 0);
|
||||
return o.finish("pixtral_rope", operand, out);
|
||||
}
|
||||
|
||||
int ref_pixtral_merge_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
/* The coordinates describe complete raster grids. Random independent indices cannot make
|
||||
* a legal fixture: callers provide the grid and its patch data together. */
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int ref_seg_mean_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
|
||||
Reference in new issue
Block a user