86 {
87 if (argc < 2) {
88 fprintf(stderr, "Usage: %s <weights.bump> [manifest.json]\n", argv[0]);
89 fprintf(stderr, "\nTests reading tokenizer data from BUMP file\n");
90 return 1;
91 }
92
93 const char *bump_path = argv[1];
94 const char *manifest_path = argc > 2 ? argv[2] : NULL;
95
96 printf("Testing BUMP tokenizer extraction\n");
97 printf("==================================\n");
98 printf("BUMP file: %s\n", bump_path);
99 if (manifest_path) printf("Manifest: %s\n", manifest_path);
100 printf("\n");
101
102
103 FILE *f = fopen(bump_path, "rb");
104 if (!f) {
105 fprintf(stderr, "Error: Cannot open %s\n", bump_path);
106 return 1;
107 }
108
109
110 BumpHeader header;
111 if (fread(&header, sizeof(header), 1, f) != 1) {
112 fprintf(stderr, "Error: Cannot read header\n");
113 fclose(f);
114 return 1;
115 }
116
117
118 if (memcmp(header.magic, "BUMPWGT4", 8) != 0) {
119 fprintf(stderr, "Error: Invalid magic: %.8s\n", header.magic);
120 fclose(f);
121 return 1;
122 }
123
124 printf("BUMP Header:\n");
125 printf(" Version: %u\n", header.version);
126 printf(" Layers: %u\n", header.num_layers);
127 printf(" Vocab size: %u\n", header.vocab_size);
128 printf(" Embed dim: %u\n", header.embed_dim);
129 printf(" Heads: %u/%u\n", header.num_heads, header.num_kv_heads);
130 printf(" Head dim: %u\n", header.head_dim);
131 printf(" Intermediate: %u\n", header.intermediate_size);
132 printf(" Context: %u\n", header.context_length);
133 printf(" Num merges: %u\n", header.num_merges);
134 printf(" Vocab bytes: %u\n", header.total_vocab_bytes);
135 printf("\n");
136
137
138 if (manifest_path) {
139 size_t vocab_offsets_off, vocab_offsets_size;
140 size_t vocab_strings_off, vocab_strings_size;
141 size_t vocab_merges_off, vocab_merges_size;
142
144 &vocab_offsets_off, &vocab_offsets_size);
146 &vocab_strings_off, &vocab_strings_size);
148 &vocab_merges_off, &vocab_merges_size);
149
150 printf("Manifest entries:\n");
151 if (have_offsets) {
152 printf(" vocab_offsets: offset=0x%lx size=%zu bytes\n",
153 vocab_offsets_off, vocab_offsets_size);
154 } else {
155 printf(" vocab_offsets: NOT FOUND\n");
156 }
157 if (have_strings) {
158 printf(" vocab_strings: offset=0x%lx size=%zu bytes\n",
159 vocab_strings_off, vocab_strings_size);
160 } else {
161 printf(" vocab_strings: NOT FOUND\n");
162 }
163 if (have_merges) {
164 printf(" vocab_merges: offset=0x%lx size=%zu bytes\n",
165 vocab_merges_off, vocab_merges_size);
166 } else {
167 printf(" vocab_merges: NOT FOUND\n");
168 }
169 printf("\n");
170
171 if (have_offsets && have_strings) {
172
173 printf("Sample tokens from BUMP:\n");
174
175
176 int32_t *
offsets = malloc(vocab_offsets_size);
177 fseek(f, vocab_offsets_off, SEEK_SET);
178 fread(
offsets, 1, vocab_offsets_size, f);
179
180
181 char *
strings = malloc(vocab_strings_size);
182 fseek(f, vocab_strings_off, SEEK_SET);
183 fread(
strings, 1, vocab_strings_size, f);
184
185 int num_tokens = vocab_offsets_size / 4;
186 for (int i = 0; i < 10 && i < num_tokens; i++) {
188 printf(
" [%d] '%s'\n", i,
token);
189 }
190 printf(" ...\n");
191 for (int i = num_tokens - 5; i < num_tokens; i++) {
192 if (i >= 10) {
194 printf(
" [%d] '%s'\n", i,
token);
195 }
196 }
197
200
201 printf("\nTokenizer successfully read from BUMP file!\n");
202 }
203 } else {
204 printf("No manifest provided - cannot locate tokenizer entries.\n");
205 printf("Run converter with --manifest-out to generate manifest.\n");
206 }
207
208 fclose(f);
209 return 0;
210}
int const int32_t const char * strings
int const int32_t * offsets
static bool read_manifest_entry(const char *json_path, const char *entry_name, size_t *out_offset, size_t *out_size)