Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Llama Common Header

From Leeroopedia
Knowledge Sources
Domains Inference, Configuration
Last Updated 2025-02-15 00:00 GMT

Overview

Master header declaring all shared data structures, parameter types, enumerations, and utility function prototypes for the llama.cpp common library.

Description

Defines the key configuration structures: common_params (master parameters for model, context, sampling, speculative decoding, vocoder, diffusion), common_params_sampling (top_k, top_p, min_p, temperature, penalties, grammar, DRY), cpu_params (thread count, affinity, scheduling priority), common_adapter_lora_info (LoRA adapter paths and scales), and common_control_vector_load_info. Also defines common_time_meas for RAII-based timing and enums for sampler types, conversation modes, and grammar triggers.

Usage

Include this header whenever code needs to configure or interact with llama.cpp models. All example programs and Ollama's Go bindings depend on the types and function declarations in this header.

Code Reference

Source Location

  • Repository: Ollama
  • File: llama/llama.cpp/common/common.h
  • Lines: 1-841

Signature

struct common_time_meas {
    common_time_meas(int64_t & t_acc, bool disable = false);
    ~common_time_meas();
    const int64_t t_start_us;
    int64_t & t_acc;
};

struct cpu_params {
    int      n_threads = -1;
    bool     cpumask[GGML_MAX_N_THREADS] = {false};
    bool     mask_valid = false;
    enum ggml_sched_priority priority = GGML_SCHED_PRIO_NORMAL;
    bool     strict_cpu = false;
    uint32_t poll = 50;
};

struct common_params_sampling {
    uint32_t seed = LLAMA_DEFAULT_SEED;
    int32_t  top_k = 40;
    float    top_p = 0.95f;
    float    min_p = 0.05f;
    float    temp  = 0.80f;
    // ... more sampling parameters
};

enum common_sampler_type {
    COMMON_SAMPLER_TYPE_DRY, COMMON_SAMPLER_TYPE_TOP_K,
    COMMON_SAMPLER_TYPE_TOP_P, COMMON_SAMPLER_TYPE_MIN_P,
    COMMON_SAMPLER_TYPE_TEMPERATURE, COMMON_SAMPLER_TYPE_XTC,
    // ...
};

Import

#include "common.h"

I/O Contract

Inputs

Name Type Required Description
n_threads int No Number of threads for inference (default: auto-detect)
seed uint32_t No Random seed for sampling (default: LLAMA_DEFAULT_SEED)
top_k int32_t No Top-K sampling parameter (default: 40)
temp float No Temperature for sampling (default: 0.80)

Outputs

Name Type Description
common_params struct Fully populated configuration for model initialization
common_params_sampling struct Sampling configuration parameters

Usage Examples

#include "common.h"

// Configure sampling parameters
common_params_sampling sparams;
sparams.temp = 0.7f;
sparams.top_p = 0.9f;
sparams.top_k = 50;
sparams.min_p = 0.05f;
sparams.penalty_repeat = 1.1f;

// Configure CPU parameters
cpu_params cpu;
cpu.n_threads = 8;
cpu.priority = GGML_SCHED_PRIO_HIGH;

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment