Skip to content

Commit eb542d3

Browse files
ikawrakowKawrakow
andauthored
Add LLAMA_DEFAULT_RMS_EPS so we can change the default (#2384)
Co-authored-by: Iwan Kawrakow <[email protected]>
1 parent 07aaa0f commit eb542d3

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

examples/baby-llama/baby-llama.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#pragma warning(disable: 4244 4267) // possible loss of data
99
#endif
1010

11-
static const float rms_norm_eps = 1e-6f;
11+
#ifdef LLAMA_DEFAULT_RMS_EPS
12+
static const float rms_norm_eps = LLAMA_DEFAULT_RMS_EPS;
13+
#else
14+
static const float rms_norm_eps = 5e-6f;
15+
#endif
1216

1317
float frand() {
1418
return (float)rand()/(float)RAND_MAX;

examples/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct gpt_params {
3434
int32_t main_gpu = 0; // the GPU that is used for scratch and small tensors
3535
float tensor_split[LLAMA_MAX_DEVICES] = {0}; // how split tensors should be distributed across GPUs
3636
int32_t n_probs = 0; // if greater than 0, output the probabilities of top n_probs tokens.
37-
float rms_norm_eps = 1e-6; // rms norm epsilon
37+
float rms_norm_eps = LLAMA_DEFAULT_RMS_EPS; // rms norm epsilon
3838
float rope_freq_base = 10000.0f; // RoPE base frequency
3939
float rope_freq_scale = 1.0f; // RoPE frequency scaling factor
4040

examples/train-text-from-scratch/train-text-from-scratch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#pragma warning(disable: 4244 4267) // possible loss of data
1717
#endif
1818

19-
static const float rms_norm_eps = 1e-6f;
19+
static const float rms_norm_eps = LLAMA_DEFAULT_RMS_EPS;
2020

2121
struct random_normal_distribution {
2222
std::mt19937 gen;

llama.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ struct llama_hparams {
186186
// LLaMAv2
187187
// TODO: load from model data hparams
188188
float f_ffn_mult = 1.0f;
189-
float f_rms_norm_eps = 1e-6f;
189+
float f_rms_norm_eps = LLAMA_DEFAULT_RMS_EPS;
190190

191191
float rope_freq_base = 10000.0f;
192192
float rope_freq_scale = 1.0f;
@@ -870,7 +870,7 @@ struct llama_context_params llama_context_default_params() {
870870
/*.n_ctx =*/ 512,
871871
/*.n_batch =*/ 512,
872872
/*.n_gqa =*/ 1,
873-
/*.rms_norm_eps =*/ 1e-6f,
873+
/*.rms_norm_eps =*/ LLAMA_DEFAULT_RMS_EPS,
874874
/*.gpu_layers =*/ 0,
875875
/*.main_gpu =*/ 0,
876876
/*.tensor_split =*/ nullptr,

llama.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
#define LLAMA_SUPPORTS_GPU_OFFLOAD
5454
#endif
5555

56+
#ifndef LLAMA_DEFAULT_RMS_EPS
57+
#define LLAMA_DEFAULT_RMS_EPS 5e-6f
58+
#endif
59+
5660
#ifdef __cplusplus
5761
extern "C" {
5862
#endif

0 commit comments

Comments
 (0)