|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "ggml.h"
|
|
|
#include <cmath>
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ggml_compute_forward_causal_conv1d(
|
|
|
const struct ggml_compute_params * params,
|
|
|
const struct ggml_tensor * src0,
|
|
|
const struct ggml_tensor * src1,
|
|
|
struct ggml_tensor * dst) {
|
|
|
|
|
|
const int nc = src0->ne[1];
|
|
|
const int nt = src0->ne[0];
|
|
|
const int nk = src1->ne[0];
|
|
|
const int dilation = params->ith;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int c = 0; c < nc; c++) {
|
|
|
for (int t = 0; t < nt; t++) {
|
|
|
float sum = 0.0f;
|
|
|
for (int k = 0; k < nk; k++) {
|
|
|
int src_t = t - k * dilation;
|
|
|
if (src_t >= 0) {
|
|
|
float val = ((float*)src0->data)[c * nt + src_t];
|
|
|
float weight = ((float*)src1->data)[c * nk + k];
|
|
|
sum += val * weight;
|
|
|
}
|
|
|
}
|
|
|
((float*)dst->data)[c * nt + t] = sum;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ggml_compute_forward_fractal_gate(
|
|
|
const struct ggml_compute_params * params,
|
|
|
const struct ggml_tensor * src0,
|
|
|
const struct ggml_tensor * src1,
|
|
|
struct ggml_tensor * dst) {
|
|
|
|
|
|
const int ne = ggml_nelements(src0);
|
|
|
const float * a = (const float *)src0->data;
|
|
|
const float * b = (const float *)src1->data;
|
|
|
float * out = (float *)dst->data;
|
|
|
|
|
|
for (int i = 0; i < ne; i++) {
|
|
|
|
|
|
float silu_a = a[i] * (1.0f / (1.0f + std::exp(-a[i])));
|
|
|
|
|
|
float sig_b = 1.0f / (1.0f + std::exp(-b[i]));
|
|
|
out[i] = silu_a * sig_b;
|
|
|
}
|
|
|
}
|
|
|
|