Implementation:Ggml org Ggml Ggml opt init
Appearance
Overview
The optimizer configuration implementation in GGML consists of two APIs that work together to initialize gradient-based optimization:
ggml_opt_default_params-- constructs a default parameter struct for the optimizerggml_opt_init-- creates a fully configured optimizer context from those parameters
API Details
ggml_opt_default_params
Signature:
struct ggml_opt_params ggml_opt_default_params(
ggml_backend_sched_t backend_sched,
enum ggml_opt_loss_type loss_type
);
Location: src/ggml-opt.cpp:L245-260
Parameters:
| Parameter | Type | Description |
|---|---|---|
backend_sched |
ggml_backend_sched_t |
Backend scheduler handle that determines where computation is executed |
loss_type |
enum ggml_opt_loss_type |
Loss function type: GGML_OPT_LOSS_TYPE_CROSS_ENTROPY (classification) or GGML_OPT_LOSS_TYPE_MEAN (regression)
|
Returns: A ggml_opt_params struct populated with the following default values:
| Field | Default Value | Description |
|---|---|---|
alpha |
0.001 | AdamW learning rate |
beta1 |
0.9 | First moment exponential decay rate |
beta2 |
0.999 | Second moment exponential decay rate |
eps |
1e-8 | Numerical stability constant |
wd |
0.0 | Weight decay coefficient |
ggml_opt_init
Signature:
ggml_opt_context_t ggml_opt_init(struct ggml_opt_params params);
Location: src/ggml-opt.cpp:L549-582
Parameters:
| Parameter | Type | Description |
|---|---|---|
params |
struct ggml_opt_params |
The optimizer parameters struct (typically obtained from ggml_opt_default_params)
|
Returns: A ggml_opt_context_t representing the fully initialized optimizer context with:
- The configured optimizer (AdamW or SGD) ready for use
- Built forward, backward, and optimizer computation graphs
Dependencies
- Header:
ggml-opt.h
Import
#include "ggml-opt.h"
Usage Example
// Obtain default AdamW parameters for cross-entropy classification struct ggml_opt_params params = ggml_opt_default_params(backend_sched, GGML_OPT_LOSS_TYPE_CROSS_ENTROPY); // Optionally override defaults params.adamw.alpha = 0.0005f; params.adamw.wd = 0.01f; // Initialize the optimizer context ggml_opt_context_t opt_ctx = ggml_opt_init(params);
Related
Source
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment