| 57 | } // namespace |
| 58 | |
| 59 | int main(int argc, char** argv) { |
| 60 | setvbuf(stdout, nullptr, _IONBF, 0); |
| 61 | std::vector<std::string> pairs = split("iq3_xxs/q5_0,iq3_xxs/iq4_nl,iq4_xs/q5_0,iq4_xs/iq4_nl,iq3_s/iq4_nl,iq2_s/iq4_nl,iq4_xs/q8_0,iq2_s/q2_0,iq3_xxs/q2_0"); |
| 62 | int nt_max = 8, experts = 3; |
| 63 | for (int i = 1; i < argc; ++i) { |
| 64 | const std::string a = argv[i]; |
| 65 | if (a == "--pairs" && i + 1 < argc) pairs = split(argv[++i]); |
| 66 | else if (a == "--nt-max" && i + 1 < argc) nt_max = std::atoi(argv[++i]); |
| 67 | else if (a == "--experts" && i + 1 < argc) experts = std::atoi(argv[++i]); |
| 68 | else { std::fprintf(stderr, "usage: cpu_dispatch_dump [--pairs a/b,...] [--nt-max 8] [--experts 3]\n"); return 2; } |
| 69 | } |
| 70 | ggml_cpu_init(); |
| 71 | for (const std::string& pair : pairs) { |
| 72 | const size_t slash = pair.find('/'); |
| 73 | const int gt = slash == std::string::npos ? -1 : type_of(pair.substr(0, slash)); |
| 74 | const int dt = slash == std::string::npos ? -1 : type_of(pair.substr(slash + 1)); |
| 75 | cpu::NativeFmt f; |
| 76 | std::string err; |
| 77 | if (gt < 0 || dt < 0 || !cpu::native_fmt(gt, dt, kH, kFF, f, err)) { |
| 78 | std::printf("%s: %s\n", pair.c_str(), err.empty() ? "unknown types" : err.c_str()); |
| 79 | continue; |
| 80 | } |
| 81 | ggml_quantize_init((ggml_type) gt); |
| 82 | ggml_quantize_init((ggml_type) dt); |
| 83 | std::mt19937 rng(4321 + gt * 64 + dt); |
| 84 | std::normal_distribution<float> nd(0.f, 0.02f), xd(0.f, 1.f); |
| 85 | std::vector<float> row((size_t) std::max(kH, kFF)); |
| 86 | const std::vector<float> imatrix((size_t) std::max(kH, kFF), 1.0f); |
| 87 | auto quant = [&](int type, uint8_t* dst, int64_t n) { |
| 88 | ggml_quantize_chunk((ggml_type) type, row.data(), dst, 0, 1, n, ggml_quantize_requires_imatrix((ggml_type) type) ? imatrix.data() : nullptr); |
| 89 | }; |
| 90 | std::vector<uint8_t> blob(f.bytes + 64); |
| 91 | std::vector<std::vector<uint8_t>> xa(kMaxT, std::vector<uint8_t>(cpu::kNativeActBytes)), ha(kMaxT, std::vector<uint8_t>(cpu::kNativeHBytes)); |
| 92 | std::vector<std::vector<float>> ffv(kMaxT, std::vector<float>(kFF)), outv(kMaxT, std::vector<float>(kH)); |
| 93 | const void* act[kMaxT]; |
| 94 | const void* hq[kMaxT]; |
| 95 | float* ff[kMaxT]; |
| 96 | float* out[kMaxT]; |
| 97 | for (int t = 0; t < kMaxT; ++t) { act[t] = xa[(size_t) t].data(); hq[t] = ha[(size_t) t].data(); ff[t] = ffv[(size_t) t].data(); out[t] = outv[(size_t) t].data(); } |
| 98 | // a Q2_0 down (or gate/up) takes the pool's own path (pool.cpp): the activation as an ActQ and Strata's Q2_0 rows, not ggml's dot |
| 99 | const bool q2_down = cpu::q2_native_kernels(f.d_type), q2_gu = cpu::q2_native_kernels(f.gu_type); |
| 100 | std::vector<cpu::ActQ> h2(q2_down ? kMaxT : 0), x2(q2_gu ? kMaxT : 0); |
| 101 | const cpu::ActQ* a2[kMaxT] = {}; |
| 102 | const cpu::ActQ* ax[kMaxT] = {}; |
| 103 | std::vector<std::vector<float>> gv(q2_gu ? kMaxT : 0, std::vector<float>(kFF)), uv(q2_gu ? kMaxT : 0, std::vector<float>(kFF)); |
| 104 | float* gp2[kMaxT] = {}; |
| 105 | float* up2[kMaxT] = {}; |
| 106 | uint64_t total = 1469598103934665603ull; |
| 107 | for (int e = 0; e < experts; ++e) { |
| 108 | for (int64_t r = 0; r < 2 * kFF; ++r) { |
| 109 | for (int64_t i = 0; i < kH; ++i) row[(size_t) i] = nd(rng); |
| 110 | quant(f.gu_type, blob.data() + (size_t) r * f.gu_row, kH); |
| 111 | } |
| 112 | for (int64_t r = 0; r < kH; ++r) { |
| 113 | for (int64_t i = 0; i < kFF; ++i) row[(size_t) i] = nd(rng); |
| 114 | quant(f.d_type, blob.data() + f.down_off + (size_t) r * f.d_row, kFF); |
| 115 | } |
| 116 | for (int t = 0; t < kMaxT; ++t) { |
nothing calls this directly
no test coverage detected