okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mac-rel (Mac Metal support) into f-144-rel6a74320ca

main
1.3 KiB25 linesraw
1// metal/tools/gguf_list.cpp - tensor directory and scalar metadata of a GGUF (name type shape offset), for the
2// Metal window's wiring.   clang++ -std=c++20 -I include metal/tools/gguf_list.cpp -o gguf_list
3#include "strata/artifact/gguf_reader.hpp"
4
5#include <cstdio>
6#include <string>
7
8int main(int argc, char** argv) {
9    if (argc < 2) { std::printf("usage: gguf_list <file.gguf> [substring]\n"); return 2; }
10    strata::GgufFile g(argv[1]);
11    const std::string f = argc > 2 ? argv[2] : "";
12    for (const auto& [k, v] : g.metadata()) {
13        if (!f.empty() && k.find(f) == std::string::npos) continue;
14        if (v.is_num()) std::printf("META %s = %g\n", k.c_str(), v.num());
15        else if (v.type == strata::MetaType::STRING) std::printf("META %s = %s\n", k.c_str(), v.s.substr(0, 80).c_str());
16        else std::printf("META %s = [%llu items]\n", k.c_str(), (unsigned long long) v.count);
17    }
18    for (const auto& t : g.tensors()) {
19        if (!f.empty() && t.name.find(f) == std::string::npos) continue;
20        std::printf("%s %s [", t.name.c_str(), t.type_name());
21        for (size_t i = 0; i < t.shape.size(); ++i) std::printf(i ? ",%llu" : "%llu", (unsigned long long) t.shape[i]);
22        std::printf("] off %llu\n", (unsigned long long) t.offset);
23    }
24    return 0;
25}