Skip to content

Commit ed09a85

Browse files
committed
Merge branch 'master' into concedo_experimental
# Conflicts: # .github/workflows/build.yml # .gitignore # CMakeLists.txt # Makefile # README.md # ci/run.sh # ggml-opencl.cpp # tests/CMakeLists.txt
2 parents 762eeb6 + a1d6df1 commit ed09a85

27 files changed

+1328
-972
lines changed

common/sampling.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ static void sampler_queue(
129129
const int n_vocab = llama_n_vocab(llama_get_model(ctx_main));
130130

131131
const float temp = params.temp;
132+
const float dynatemp_range = params.dynatemp_range;
133+
const float dynatemp_exponent = params.dynatemp_exponent;
132134
const int32_t top_k = params.top_k <= 0 ? n_vocab : params.top_k;
133135
const float top_p = params.top_p;
134136
const float min_p = params.min_p;
@@ -143,7 +145,15 @@ static void sampler_queue(
143145
case 'y': llama_sample_typical (ctx_main, &cur_p, typical_p, min_keep); break;
144146
case 'p': llama_sample_top_p (ctx_main, &cur_p, top_p, min_keep); break;
145147
case 'm': llama_sample_min_p (ctx_main, &cur_p, min_p, min_keep); break;
146-
case 't': llama_sample_temp (ctx_main, &cur_p, temp); break;
148+
case 't':
149+
if (dynatemp_range > 0) {
150+
float dynatemp_min = std::max(0.0f, temp - dynatemp_range);
151+
float dynatemp_max = std::max(0.0f, temp + dynatemp_range);
152+
llama_sample_entropy(ctx_main, &cur_p, dynatemp_min, dynatemp_max, dynatemp_exponent);
153+
} else {
154+
llama_sample_temp(ctx_main, &cur_p, temp);
155+
}
156+
break;
147157
default : break;
148158
}
149159
}

common/sampling.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ typedef struct llama_sampling_params {
1818
float tfs_z = 1.00f; // 1.0 = disabled
1919
float typical_p = 1.00f; // 1.0 = disabled
2020
float temp = 0.80f; // <= 0.0 to sample greedily, 0.0 to not output probabilities
21+
float dynatemp_range = 0.00f; // 0.0 = disabled
22+
float dynatemp_exponent = 1.00f; // controls how entropy maps to temperature in dynamic temperature sampler
2123
int32_t penalty_last_n = 64; // last n tokens to penalize (0 = disable penalty, -1 = context size)
2224
float penalty_repeat = 1.10f; // 1.0 = disabled
2325
float penalty_freq = 0.00f; // 0.0 = disabled
2426
float penalty_present = 0.00f; // 0.0 = disabled
2527
int32_t mirostat = 0; // 0 = disabled, 1 = mirostat, 2 = mirostat 2.0
2628
float mirostat_tau = 5.00f; // target entropy
2729
float mirostat_eta = 0.10f; // learning rate
28-
bool dynatemp_range = 0.00f; // dynamic temperature range
2930
bool penalize_nl = true; // consider newlines as a repeatable token
3031
std::string samplers_sequence = "kfypmt"; // top_k, tail_free, typical_p, top_p, min_p, temp
3132

examples/llama.android/app/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ android {
3030
}
3131
externalNativeBuild {
3232
cmake {
33+
arguments += "-DCMAKE_BUILD_TYPE=Release"
3334
cppFlags += listOf()
3435
arguments += listOf()
3536
}

examples/pydantic-models-to-grammar-examples.py

+6-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Function calling example using pydantic models.
22
import datetime
3+
import importlib
34
import json
45
from enum import Enum
5-
from typing import Union, Optional
6+
from typing import Optional, Union
67

78
import requests
89
from pydantic import BaseModel, Field
9-
10-
import importlib
11-
from pydantic_models_to_grammar import generate_gbnf_grammar_and_documentation, convert_dictionary_to_pydantic_model, add_run_method_to_dynamic_model, create_dynamic_model_from_function
10+
from pydantic_models_to_grammar import (add_run_method_to_dynamic_model, convert_dictionary_to_pydantic_model,
11+
create_dynamic_model_from_function, generate_gbnf_grammar_and_documentation)
1212

1313

1414
# Function to get completion on the llama.cpp server with grammar.
@@ -35,15 +35,15 @@ def run(self):
3535
print(self.message)
3636

3737

38-
# Enum for the calculator function.
38+
# Enum for the calculator tool.
3939
class MathOperation(Enum):
4040
ADD = "add"
4141
SUBTRACT = "subtract"
4242
MULTIPLY = "multiply"
4343
DIVIDE = "divide"
4444

4545

46-
# Very simple calculator tool for the agent.
46+
# Simple pydantic calculator tool for the agent that can add, subtract, multiply, and divide. Docstring and description of fields will be used in system prompt.
4747
class Calculator(BaseModel):
4848
"""
4949
Perform a math operation on two numbers.
@@ -148,37 +148,6 @@ def get_current_datetime(output_format: Optional[str] = None):
148148
return datetime.datetime.now().strftime(output_format)
149149

150150

151-
# Enum for the calculator tool.
152-
class MathOperation(Enum):
153-
ADD = "add"
154-
SUBTRACT = "subtract"
155-
MULTIPLY = "multiply"
156-
DIVIDE = "divide"
157-
158-
159-
160-
# Simple pydantic calculator tool for the agent that can add, subtract, multiply, and divide. Docstring and description of fields will be used in system prompt.
161-
class Calculator(BaseModel):
162-
"""
163-
Perform a math operation on two numbers.
164-
"""
165-
number_one: Union[int, float] = Field(..., description="First number.")
166-
operation: MathOperation = Field(..., description="Math operation to perform.")
167-
number_two: Union[int, float] = Field(..., description="Second number.")
168-
169-
def run(self):
170-
if self.operation == MathOperation.ADD:
171-
return self.number_one + self.number_two
172-
elif self.operation == MathOperation.SUBTRACT:
173-
return self.number_one - self.number_two
174-
elif self.operation == MathOperation.MULTIPLY:
175-
return self.number_one * self.number_two
176-
elif self.operation == MathOperation.DIVIDE:
177-
return self.number_one / self.number_two
178-
else:
179-
raise ValueError("Unknown operation.")
180-
181-
182151
# Example function to get the weather
183152
def get_current_weather(location, unit):
184153
"""Get the current weather in a given location"""

0 commit comments

Comments
 (0)