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

Function gguf_add_tensor

ggml.c:20138–20166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20136}
20137
20138void gguf_add_tensor(
20139 struct gguf_context * ctx,
20140 const struct ggml_tensor * tensor) {
20141 const int idx = ctx->header.n_tensors;
20142 ctx->infos = realloc(ctx->infos, (idx + 1)*sizeof(struct gguf_tensor_info));
20143
20144 ctx->infos[idx].name.n = strlen(tensor->name);
20145 ctx->infos[idx].name.data = strdup(tensor->name);
20146
20147 for (int i = 0; i < GGML_MAX_DIMS; ++i) {
20148 ctx->infos[idx].ne[i] = 1;
20149 }
20150
20151 ctx->infos[idx].n_dims = tensor->n_dims;
20152 for (int i = 0; i < tensor->n_dims; i++) {
20153 ctx->infos[idx].ne[i] = tensor->ne[i];
20154 }
20155
20156 ctx->infos[idx].type = tensor->type;
20157 ctx->infos[idx].offset = 0;
20158 ctx->infos[idx].data = tensor->data;
20159 ctx->infos[idx].size = ggml_nbytes(tensor);
20160
20161 if (ctx->header.n_tensors > 0) {
20162 ctx->infos[idx].offset = ctx->infos[idx - 1].offset + GGML_PAD(ctx->infos[idx - 1].size, ctx->alignment);
20163 }
20164
20165 ctx->header.n_tensors++;
20166}
20167
20168void gguf_set_tensor_type(struct gguf_context * ctx, const char * name, enum ggml_type type) {
20169 const int idx = gguf_find_tensor(ctx, name);

Callers 8

save_opt_context_ggufFunction · 0.50
export_loraFunction · 0.50
clip_model_quantizeFunction · 0.50
save_llama_model_ggufFunction · 0.50
save_as_llama_modelFunction · 0.50
save_llama_lora_ggufFunction · 0.50
gguf_ex_writeFunction · 0.50

Calls 1

ggml_nbytesFunction · 0.70

Tested by

no test coverage detected