Repository: ggerganov/llama.cpp
File: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp (C++)

Code before:

    int   lbfgs_n_iter;
    int   adam_n_iter;
    float adam_alpha;
    float adam_decay;

    int mem_model_gb;
    int mem_compute_gb;
    int mem_compute0_gb;
    int mem_compute1_gb;
};

static void print_params(struct my_llama_hparams * params) {
    LOG_INF("%s: n_vocab:   %u\n", __func__, params->n_vocab);
    LOG_INF("%s: n_ctx:     %u\n", __func__, params->n_ctx);
    LOG_INF("%s: n_embd:    %u\n", __func__, params->n_embd);
    LOG_INF("%s: n_mult:    %u\n", __func__, params->n_mult);
    LOG_INF("%s: n_head:    %u\n", __func__, params->n_head);
    LOG_INF("%s: n_head_kv: %u\n", __func__, params->n_head_kv);
    LOG_INF("%s: n_ff:      %u\n", __func__, params->n_ff);
    LOG_INF("%s: n_layer:   %u\n", __func__, params->n_layer);
    LOG_INF("%s: n_rot:     %u\n", __func__, params->n_rot);
}

static void print_tensor_info(const struct ggml_context * ctx) {
    for (auto t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
        LOG_INF("%s: Allocating ", __func__);
        int64_t total = 1;
        int i = 0;
        for (; i < ggml_n_dims(t); ++i) {
            if (i > 0) LOG("x ");
            LOG("[%" PRId64 "] ", t->ne[i]);
            total *= t->ne[i];
        }
        if (i > 1) LOG("= [%" PRId64 "] ", total);
        LOG("float space for %s\n", ggml_get_name(t));
    }
}

static void init_model(struct my_llama_model * model) {
    const auto & hparams = model->hparams;

    const uint32_t n_embd  = hparams.n_embd;
    const uint32_t n_layer = hparams.n_layer;
    const uint32_t n_vocab = hparams.n_vocab;

    const uint32_t n_multiqueries = hparams.n_head_kv <= 0 || hparams.n_head_kv >= hparams.n_head ? 1 : hparams.n_head / hparams.n_head_kv;

    const uint32_t n_ff = hparams.n_ff;
    struct ggml_context * ctx = model->ctx;


Review comment (suggestion):
```suggestion
    for (auto * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
```

See https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md#coding-guidelines

Code after:

    int   lbfgs_n_iter;
    int   adam_n_iter;
    float adam_alpha;
    float adam_decay;

    int mem_model_gb;
    int mem_compute_gb;
    int mem_compute0_gb;
    int mem_compute1_gb;
};

static void print_params(struct my_llama_hparams * params) {
    LOG_INF("%s: n_vocab:   %u\n", __func__, params->n_vocab);
    LOG_INF("%s: n_ctx:     %u\n", __func__, params->n_ctx);
    LOG_INF("%s: n_embd:    %u\n", __func__, params->n_embd);
    LOG_INF("%s: n_mult:    %u\n", __func__, params->n_mult);
    LOG_INF("%s: n_head:    %u\n", __func__, params->n_head);
    LOG_INF("%s: n_head_kv: %u\n", __func__, params->n_head_kv);
    LOG_INF("%s: n_ff:      %u\n", __func__, params->n_ff);
    LOG_INF("%s: n_layer:   %u\n", __func__, params->n_layer);
    LOG_INF("%s: n_rot:     %u\n", __func__, params->n_rot);
}

static void print_tensor_info(const struct ggml_context * ctx) {
    for (auto * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
        LOG_INF("%s: Allocating ", __func__);
        int64_t total = 1;
        int i = 0;
        for (; i < ggml_n_dims(t); ++i) {
            if (i > 0) { LOG_INF("x "); }
            LOG_INF("[%" PRId64 "] ", t->ne[i]);
            total *= t->ne[i];
        }
        if (i > 1) { LOG_INF("= [%" PRId64 "] ", total); }
        LOG_INF("float space for %s\n", ggml_get_name(t));
    }
}

static void init_model(struct my_llama_model * model) {
    const auto & hparams = model->hparams;

    const uint32_t n_embd  = hparams.n_embd;
    const uint32_t n_layer = hparams.n_layer;
    const uint32_t n_vocab = hparams.n_vocab;

    const uint32_t n_multiqueries = hparams.n_head_kv <= 0 || hparams.n_head_kv >= hparams.n_head ? 1 : hparams.n_head / hparams.n_head_kv;

    const uint32_t n_ff = hparams.n_ff;
    struct ggml_context * ctx = model->ctx;