MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / write_tensor

Function write_tensor

examples/finetune/finetune.cpp:1101–1125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1099};
1100
1101static void write_tensor(struct llama_file * file, struct ggml_tensor * tensor, const char * name) {
1102 if (tensor == NULL) {
1103 file->write_u32(0);
1104 file->write_u32(0);
1105 file->write_u32(GGML_TYPE_F32);
1106 file->seek((0-file->tell()) & 31, SEEK_CUR);
1107 return;
1108 }
1109 if (name == NULL) {
1110 name = ggml_get_name(tensor);
1111 }
1112 uint32_t name_len = strlen(name);
1113 uint32_t nd = tensor->n_dims;
1114 uint32_t ne[4] = { (uint32_t)tensor->ne[0],
1115 (uint32_t)tensor->ne[1],
1116 (uint32_t)tensor->ne[2],
1117 (uint32_t)tensor->ne[3] };
1118 file->write_u32(nd);
1119 file->write_u32(name_len);
1120 file->write_u32(tensor->type);
1121 file->write_raw(ne, sizeof(ne[0]) * nd);
1122 file->write_raw(name, name_len);
1123 file->seek((0-file->tell()) & 31, SEEK_CUR);
1124 file->write_raw(tensor->data, ggml_nbytes(tensor));
1125}
1126
1127static void save_as_llama_lora(const char * filename, struct my_llama_lora * lora) {
1128 printf("%s: saving to %s\n", __func__, filename);

Callers 1

save_as_llama_loraFunction · 0.85

Calls 6

ggml_get_nameFunction · 0.50
ggml_nbytesFunction · 0.50
write_u32Method · 0.45
seekMethod · 0.45
tellMethod · 0.45
write_rawMethod · 0.45

Tested by

no test coverage detected