-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathtest_subsampling.cpp
More file actions
35 lines (32 loc) · 1.45 KB
/
Copy pathtest_subsampling.cpp
File metadata and controls
35 lines (32 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "subsampling.hpp"
#include "model_loader.hpp"
#include "parity.hpp"
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cstdint>
int main(){
const char* gguf = std::getenv("PARAKEET_TEST_GGUF");
const char* base = std::getenv("PARAKEET_TEST_BASELINE");
if(!gguf||!base){ std::fprintf(stderr,"env not set; skip\n"); return 77; }
pk::ModelLoader ml; if(!ml.load(gguf)) return 1;
// Input: baseline "mel" is [n_mels, T] row-major (feat-major inner=T).
std::vector<float> mel; std::vector<int64_t> mshape;
if(!pktest::load_baseline(base, "mel", mel, mshape)) return 1;
if(mshape.size()!=2){ std::fprintf(stderr,"mel shape rank=%zu\n", mshape.size()); return 1; }
const int n_mels = (int)mshape[0];
const int T = (int)mshape[1];
pk::Subsampling sub(ml);
std::vector<float> out; int Tout=0, d_model=0;
sub.forward(mel, n_mels, T, out, Tout, d_model);
// Reference: subsampling_out is [T', d_model] row-major.
std::vector<float> ref; std::vector<int64_t> rshape;
if(!pktest::load_baseline(base, "subsampling_out", ref, rshape)) return 1;
if(rshape.size()!=2 || (int)rshape[0]!=Tout || (int)rshape[1]!=d_model){
std::fprintf(stderr,"shape mismatch got=[%d,%d] ref=[%lld,%lld]\n",
Tout, d_model, (long long)rshape[0], (long long)rshape[1]);
return 1;
}
bool ok = pktest::compare(out, ref, "subsampling", /*atol*/1e-2f, /*rtol*/1e-2f);
return ok?0:1;
}