MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / get_handcrafted_file

Function get_handcrafted_file

subprojects/llama.cpp/tests/test-gguf.cpp:163–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163static FILE * get_handcrafted_file(const unsigned int seed, const enum handcrafted_file_type hft, const int extra_bytes = 0) {
164 FILE * file = tmpfile();
165
166 if (!file) {
167 return file;
168 }
169
170 std::mt19937 rng(seed);
171 uint32_t alignment = GGUF_DEFAULT_ALIGNMENT;
172
173 if (hft == HANDCRAFTED_HEADER_BAD_MAGIC) {
174 const char bad_magic[4] = {'F', 'U', 'G', 'G'};
175 helper_write(file, bad_magic, sizeof(bad_magic));
176 } else {
177 helper_write(file, GGUF_MAGIC, 4);
178 }
179
180 if (hft == HANDCRAFTED_HEADER_BAD_VERSION_0) {
181 const uint32_t version = 0;
182 helper_write(file, version);
183 } else if (hft == HANDCRAFTED_HEADER_BAD_VERSION_1) {
184 const uint32_t version = 1;
185 helper_write(file, version);
186 } else if (hft == HANDCRAFTED_HEADER_BAD_VERSION_FUTURE) {
187 const uint32_t version = GGUF_VERSION + 1;
188 helper_write(file, version);
189 } else {
190 const uint32_t version = GGUF_VERSION;
191 helper_write(file, version);
192 }
193
194 std::vector<tensor_config_t> tensor_configs;
195 if (hft >= offset_has_tensors) {
196 tensor_configs = get_tensor_configs(rng);
197 }
198
199 if (hft == HANDCRAFTED_HEADER_BAD_N_TENSORS) {
200 const uint64_t n_tensors = -1;
201 helper_write(file, n_tensors);
202 } else {
203 const uint64_t n_tensors = tensor_configs.size();
204 helper_write(file, n_tensors);
205 }
206
207 std::vector<std::pair<enum gguf_type, enum gguf_type>> kv_types;
208 if (hft >= offset_has_kv) {
209 kv_types = get_kv_types(rng);
210 }
211 {
212 uint64_t n_kv = kv_types.size();
213 if (hft == HANDCRAFTED_KV_BAD_ALIGN ||
214 hft == HANDCRAFTED_TENSORS_BAD_ALIGN || hft == HANDCRAFTED_TENSORS_CUSTOM_ALIGN ||
215 hft == HANDCRAFTED_DATA_BAD_ALIGN || hft == HANDCRAFTED_DATA_CUSTOM_ALIGN) {
216
217 n_kv += 1;
218 } else if (hft == HANDCRAFTED_HEADER_BAD_N_KV) {
219 n_kv = -1;
220 }

Callers 1

test_handcrafted_fileFunction · 0.85

Calls 14

helper_writeFunction · 0.85
get_tensor_configsFunction · 0.85
get_kv_typesFunction · 0.85
to_stringFunction · 0.85
gguf_type_sizeFunction · 0.85
expect_context_not_nullFunction · 0.85
ggml_type_sizeFunction · 0.85
powFunction · 0.85
ggml_blck_sizeFunction · 0.85
ggml_row_sizeFunction · 0.85
gguf_typeEnum · 0.70
sizeMethod · 0.65

Tested by

no test coverage detected