-
-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sampling parameters client-side config #81
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe recent changes introduce a new data class, Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (3)
glados_config.yml (2)
23-25
: Consider implementing the remaining parameters.The TODO comment suggests that parameters from
min_p
onwards are not currently functional. Consider implementing these parameters in future updates to enhance configurability.
26-32
: Review Default Values and Implementation StatusThe default values for
LlamaGenConfig
parameters inglados_config.yml
have some context indicating a recommended temperature setting. However, a TODO comment suggests that parameters frommin_p
onwards are not currently functional. This could imply a misalignment between the default values and their intended use, especially if these parameters are expected to impact the balance between accuracy and creativity. Please review and ensure all parameters are implemented and align with the intended use.
glados_config.yml
: Check the implementation status and intended use ofmin_p
and other parameters.Analysis chain
Ensure default values align with intended use.
The default values for
temperature
,dynatemp_range
,dynatemp_exponent
,top_k
,top_p
, andmin_p
should be reviewed to ensure they align with the desired balance between accuracy and creativity as mentioned in the PR summary.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the default values for LlamaGenConfig parameters in the codebase. # Test: Search for default values in the codebase. Expect: Consistency with glados_config.yml. rg --type yaml -A 5 $'LlamaGenConfig'Length of output: 252
Script:
#!/bin/bash # Description: Search for mentions of LlamaGenConfig parameters in the codebase for additional context. # Search for temperature, dynatemp_range, dynatemp_exponent, top_k, top_p, and min_p in the codebase. rg 'temperature|dynatemp_range|dynatemp_exponent|top_k|top_p|min_p' --type yaml --type md --type txtLength of output: 523
glados.py (1)
48-54
: Inconsistency intemperature
default value between code and configurationThe
temperature
parameter in theLlamaGenConfig
class has a default value of0.7
, while theglados_config.yml
specifies0.1
. Consider aligning these values to ensure consistency and avoid unexpected behavior.
Code (glados.py)
temperature: 0.7
Configuration (glados_config.yml)
temperature: 0.1
Analysis chain
Ensure parameter defaults align with configuration.
The default values for parameters in
LlamaGenConfig
should be consistent with those inglados_config.yml
to prevent discrepancies.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistency of default values between LlamaGenConfig class and glados_config.yml. # Test: Search for parameter definitions in the codebase. Expect: Consistent values with glados_config.yml. rg --type python -A 5 $'class LlamaGenConfig'Length of output: 77
Script:
#!/bin/bash # Description: Verify the consistency of default values between LlamaGenConfig class and glados_config.yml. # Find the LlamaGenConfig class definition in Python files rg 'class LlamaGenConfig' -A 5 --lang py # Find the glados_config.yml file and display its contents fd --type f --name 'glados_config.yml' --exec catLength of output: 752
Script:
#!/bin/bash # Description: Verify the consistency of default values between LlamaGenConfig class and glados_config.yml. # Find the LlamaGenConfig class definition in Python files rg 'class LlamaGenConfig' -A 5 # Find and display the contents of glados_config.yml fd glados_config.yml -x catLength of output: 2889
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- glados.py (7 hunks)
- glados_config.yml (1 hunks)
Additional comments not posted (3)
glados.py (3)
103-108
: Verify parameter initialization.Ensure that the new parameters (
temperature
,dynatemp_range
,dynatemp_exponent
,top_k
,top_p
,min_p
) are correctly initialized and utilized within the class.Verification successful
Parameters are correctly initialized and utilized.
The parameters
temperature
,dynatemp_range
,dynatemp_exponent
,top_k
,top_p
, andmin_p
are properly initialized and used within theglados.py
file. No issues found with their implementation.
temperature
: Initialized and used.dynatemp_range
: Initialized and used.dynatemp_exponent
: Initialized and used.top_k
: Initialized and used.top_p
: Initialized and used.min_p
: Initialized and used.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify usage of Llama generation parameters in VoiceRecognition class. # Test: Search for parameter usage in the codebase. Expect: Consistent and correct usage. rg --type python -A 5 $'def __init__' --context 5 $'self.temperature'Length of output: 98
Script:
#!/bin/bash # Description: Verify usage of Llama generation parameters in VoiceRecognition class. # Test: Search for parameter usage in the codebase. Expect: Consistent and correct usage. rg --type py -A 5 $'def __init__' --context 5 $'self.temperature'Length of output: 120
Script:
#!/bin/bash # Description: Verify usage of Llama generation parameters in VoiceRecognition class. # Test: Search for parameter usage in the codebase. Expect: Consistent and correct usage. rg --type py -A 5 'def __init__' | rg 'self\.temperature'Length of output: 59
Script:
#!/bin/bash # Description: Verify usage of all Llama generation parameters in VoiceRecognition class. # Test: Search for the usage of all parameters in the codebase. Expect: Consistent and correct usage. for param in temperature dynatemp_range dynatemp_exponent top_k top_p min_p; do echo "Searching for self.$param usage:" rg --type py "self\.$param" echo "" doneLength of output: 1862
514-519
: Ensure proper parameter inclusion in LLM request.Verify that the Llama generation parameters are correctly included in the request data sent to the LLM server.
Verification successful
Parameters are correctly included in LLM server requests.
The Llama generation parameters are included in the JSON payload of a
requests.post
call, ensuring they are sent to the LLM server as expected.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify inclusion of Llama generation parameters in LLM server requests. # Test: Search for parameter inclusion in requests. Expect: Correct parameter usage. rg --type python -A 5 $'"temperature": self.temperature'Length of output: 88
Script:
#!/bin/bash # Description: Verify inclusion of Llama generation parameters in LLM server requests. # Test: Search for parameter inclusion in requests. Expect: Correct parameter usage. rg --type py -A 5 $'"temperature": self.temperature'Length of output: 413
Script:
#!/bin/bash # Description: Verify usage of the parameters dictionary in HTTP requests. # Test: Search for HTTP request functions using the parameters dictionary. rg --type py 'requests.post|requests.get|http.client' -A 10Length of output: 1388
Line range hint
204-226
:
Verify integration of LlamaGenConfig parameters.Ensure that the integration of
LlamaGenConfig
parameters in thefrom_config
method is consistent and correctly implemented.
@classmethod | ||
def from_yaml(cls, filename): | ||
config = {} | ||
with open(filename, 'r') as file: | ||
data = yaml.safe_load(file) | ||
if 'LlamaGenConfig' in data: | ||
config.update(data['LlamaGenConfig']) | ||
return cls(**config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure robust error handling in from_yaml
.
The from_yaml
method should include error handling for file access and YAML parsing to prevent runtime errors.
@classmethod
def from_yaml(cls, filename):
config = {}
try:
with open(filename, 'r') as file:
data = yaml.safe_load(file)
if 'LlamaGenConfig' in data:
config.update(data['LlamaGenConfig'])
except FileNotFoundError:
logger.error(f"Configuration file {filename} not found.")
except yaml.YAMLError as e:
logger.error(f"Error parsing YAML file: {e}")
return cls(**config)
#LLama generation/sampler parameters. | ||
self.temperature = temperature | ||
self.dynatemp_range = dynatemp_range | ||
self.dynatemp_exponent = dynatemp_exponent | ||
self.top_k = top_k | ||
self.top_p = top_p | ||
self.min_p = min_p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding parameter validation.
Adding validation for the Llama generation parameters can prevent invalid configurations from causing runtime errors.
# Example validation logic
if not (0.0 <= self.temperature <= 1.0):
raise ValueError("Temperature must be between 0.0 and 1.0")
# Repeat similar checks for other parameters as needed
Much appreciated! I will be leaving today for an overseas holiday, I can review this when I'm back next month. |
Thanks for the quick response and enjoy your holiday! |
@Skyrion9 I've done a big refactor, could you reintegrate your changes? |
I'll have a look after Sunday |
6bc2bb3
to
f74ac90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
glados.py (1)
509-514
: Handle optional generation parameters in the data payloadWhen constructing the
data
dictionary for the LLM server, if any generation parameter isNone
, it could cause issues with the server if it doesn't handleNone
values appropriately. Ensure that only parameters with valid values are included in the payload.Modify the
data
dictionary construction as follows:data = { "model": self.model, "stream": True, "messages": self.messages, } # Add generation parameters only if they have valid values gen_params = { "temperature": self.temperature, "dynatemp_range": self.dynatemp_range, "dynatemp_exponent": self.dynatemp_exponent, "top_k": self.top_k, "top_p": self.top_p, "min_p": self.min_p, } # Filter out None values gen_params = {k: v for k, v in gen_params.items() if v is not None} data.update(gen_params)glados_config.yml (1)
29-56
: Remove unused or unimplemented parametersThe configuration file includes several parameters that are commented out and marked as TODO. While it's helpful to keep track of potential future configurations, having numerous commented-out lines can clutter the configuration file and may cause confusion.
Consider creating a separate documentation section or issue tracker entry to list unimplemented parameters and remove the commented-out lines from the configuration file for clarity.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
glados.py
(7 hunks)glados_config.yml
(1 hunks)
🔇 Additional comments (3)
glados.py (2)
53-61
: Ensure robust error handling infrom_yaml
methodThe
from_yaml
method currently lacks error handling, which could lead to unhandled exceptions if the configuration file is missing or contains invalid YAML. To prevent runtime errors, add error handling for file access and YAML parsing.Apply this diff to include error handling:
@classmethod def from_yaml(cls, filename): config = {} try: with open(filename, 'r') as file: data = yaml.safe_load(file) if 'LlamaGenConfig' in data: config.update(data['LlamaGenConfig']) except FileNotFoundError: logger.error(f"Configuration file {filename} not found.") except yaml.YAMLError as e: logger.error(f"Error parsing YAML file: {e}") return cls(**config)
160-167
: Consider adding parameter validation for generation parametersTo ensure that the Llama generation parameters are within valid ranges and to prevent runtime errors, consider adding validation checks for each parameter in the
__init__
method.Example validation logic:
if not (0.0 <= self.temperature <= 1.0): raise ValueError("Temperature must be between 0.0 and 1.0") if self.top_k < 0: raise ValueError("top_k must be non-negative") if not (0.0 <= self.top_p <= 1.0): raise ValueError("top_p must be between 0.0 and 1.0") # Add similar checks for other parameters as neededglados_config.yml (1)
23-28
: Ensure consistency between default values in code and configurationThe
temperature
parameter in the configuration file is set to0.1
, while the default value in the code is0.7
. Ensure that this difference is intentional and aligns with the desired behavior of the model.If the lower temperature of
0.1
is intended for specific model performance (e.g., to reduce output variability with Llama 3.1), then no action is needed. Otherwise, consider adjusting the value to match the default or adding comments to clarify the choice.
temperature = float, | ||
dynatemp_range = float, | ||
dynatemp_exponent = float, | ||
top_k = int, | ||
top_p = float, | ||
min_p = float, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct default parameter assignments in __init__
method
The default parameter values for temperature
, dynatemp_range
, dynatemp_exponent
, top_k
, top_p
, and min_p
are incorrectly set to type objects (float
and int
) instead of actual default values. This causes these parameters to be initialized with type objects, which is unintended and will lead to errors during execution.
Apply this diff to assign the correct default values:
def __init__(
self,
voice_model: str,
speaker_id: int,
completion_url: str,
model: str,
api_key: str | None = None,
wake_word: str | None = None,
personality_preprompt: Sequence[dict[str, str]] = DEFAULT_PERSONALITY_PREPROMPT,
announcement: str | None = None,
interruptible: bool = True,
- temperature = float,
- dynatemp_range = float,
- dynatemp_exponent = float,
- top_k = int,
- top_p = float,
- min_p = float,
+ temperature: float = 0.7,
+ dynatemp_range: float = 0.0,
+ dynatemp_exponent: float = 1.1,
+ top_k: int = 40,
+ top_p: float = 0.95,
+ min_p: float = 0.05,
):
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
temperature = float, | |
dynatemp_range = float, | |
dynatemp_exponent = float, | |
top_k = int, | |
top_p = float, | |
min_p = float, | |
temperature: float = 0.7, | |
dynatemp_range: float = 0.0, | |
dynatemp_exponent: float = 1.1, | |
top_k: int = 40, | |
top_p: float = 0.95, | |
min_p: float = 0.05, |
pretty, doesn't error otherwise. Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
glados.py (3)
44-51
: Add docstring to document the parameters.The
LlamaGenConfig
class should include a docstring explaining each parameter's purpose and valid ranges.@dataclass class LlamaGenConfig: + """Configuration for LLaMA model's sampling parameters. + + Args: + temperature (float): Controls randomness in generation. Range: 0.0 to 1.0 + dynatemp_range (float): Range for dynamic temperature adjustment + dynatemp_exponent (float): Exponent for dynamic temperature adjustment + top_k (int): Limits vocabulary to k most likely tokens. Range: > 0 + top_p (float): Cumulative probability cutoff. Range: 0.0 to 1.0 + min_p (float): Minimum probability threshold. Range: 0.0 to 1.0 + """
160-167
: Use consistent comment style.Replace the inline comment with a docstring to maintain consistency with the rest of the codebase.
- #LLama generation/sampler parameters. + # LLaMA generation/sampler parameters + """ + Instance variables for LLaMA model's sampling parameters. + These parameters control the text generation behavior. + """
Line range hint
201-224
: Add return type hint tofrom_config
.The method should specify its return type for better type safety.
- def from_config(cls, config: GladosConfig, llama_gen_config: LlamaGenConfig): + def from_config(cls, config: GladosConfig, llama_gen_config: LlamaGenConfig) -> "Glados":
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
glados.py
(7 hunks)
🔇 Additional comments (4)
glados.py (4)
53-60
: Add error handling infrom_yaml
.The method should handle file access and YAML parsing errors gracefully.
100-105
: Fix default parameter assignments.The parameters are incorrectly using type objects (
float
,int
) as default values instead of actual values.
509-514
: LGTM!The sampling parameters are correctly included in the request data.
608-613
: 🛠️ Refactor suggestionAdd error handling for config loading.
The function should handle potential exceptions when loading the config files to provide meaningful error messages.
def start() -> None: """Set up the LLM server and start GlaDOS.""" - glados_config = GladosConfig.from_yaml("glados_config.yml") + try: + glados_config = GladosConfig.from_yaml("glados_config.yml") + llama_gen_config = LlamaGenConfig.from_yaml("glados_config.yml") + except FileNotFoundError: + logger.error("Configuration file 'glados_config.yml' not found.") + sys.exit(1) + except yaml.YAMLError as e: + logger.error(f"Error parsing configuration file: {e}") + sys.exit(1) - # Load LLama server generation/sampling parameters from YAML file - llama_gen_config = LlamaGenConfig.from_yaml("glados_config.yml") - glados = Glados.from_config(glados_config, llama_gen_config)Likely invalid or redundant comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
glados.py (3)
44-51
: Add docstring to document the parameters.The
LlamaGenConfig
class should include a docstring explaining each parameter's purpose and valid ranges.@dataclass class LlamaGenConfig: + """Configuration for LLaMA model's sampling parameters. + + Args: + temperature (float): Controls randomness in generation. Range: 0.0 to 1.0 + dynatemp_range (float): Range for dynamic temperature adjustment + dynatemp_exponent (float): Exponent for dynamic temperature adjustment + top_k (int): Limits vocabulary to k most likely tokens. Range: > 0 + top_p (float): Cumulative probability cutoff. Range: 0.0 to 1.0 + min_p (float): Minimum probability threshold. Range: 0.0 to 1.0 + """
160-167
: Use consistent comment style.Replace the inline comment with a docstring to maintain consistency with the rest of the codebase.
- #LLama generation/sampler parameters. + # LLaMA generation/sampler parameters + """ + Instance variables for LLaMA model's sampling parameters. + These parameters control the text generation behavior. + """
Line range hint
201-224
: Add return type hint tofrom_config
.The method should specify its return type for better type safety.
- def from_config(cls, config: GladosConfig, llama_gen_config: LlamaGenConfig): + def from_config(cls, config: GladosConfig, llama_gen_config: LlamaGenConfig) -> "Glados":
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
glados.py
(7 hunks)
🔇 Additional comments (4)
glados.py (4)
53-60
: Add error handling infrom_yaml
.The method should handle file access and YAML parsing errors gracefully.
100-105
: Fix default parameter assignments.The parameters are incorrectly using type objects (
float
,int
) as default values instead of actual values.
509-514
: LGTM!The sampling parameters are correctly included in the request data.
608-613
: 🛠️ Refactor suggestionAdd error handling for config loading.
The function should handle potential exceptions when loading the config files to provide meaningful error messages.
def start() -> None: """Set up the LLM server and start GlaDOS.""" - glados_config = GladosConfig.from_yaml("glados_config.yml") + try: + glados_config = GladosConfig.from_yaml("glados_config.yml") + llama_gen_config = LlamaGenConfig.from_yaml("glados_config.yml") + except FileNotFoundError: + logger.error("Configuration file 'glados_config.yml' not found.") + sys.exit(1) + except yaml.YAMLError as e: + logger.error(f"Error parsing configuration file: {e}") + sys.exit(1) - # Load LLama server generation/sampling parameters from YAML file - llama_gen_config = LlamaGenConfig.from_yaml("glados_config.yml") - glados = Glados.from_config(glados_config, llama_gen_config)Likely invalid or redundant comment.
Hello I've adopted the changes to latest main, however I'm unable to test if the parameters indeed apply in this branch due to the fact that I've an AMD GPU on Windows which can't run Ollama. Assuming the APIs support the parameters it should work as intended, but needs testing. |
@Skyrion9 thanks! |
First off, love the project, one thing has been bothering me was that I couldn't change the sampling parameters on client-side. With llama3.1 there's more repetition and temperatures above 0.2 are difficult to work with in that if you don't give the AI a clear goal it might go on a tangent.
Added the most popular sampling parameters into glados_config.yml to allow users to customize the sampling on client-side. This is helpful for a few reasons:
Testing/Edge cases
TODOs
Notes
Summary by CodeRabbit
New Features
LlamaGenConfig
, enhancing the control over Llama generation parameters.Improvements
Glados
class to support new parameters for improved Llama generation.