Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Skyrion9
Copy link
Contributor

@Skyrion9 Skyrion9 commented Aug 14, 2024

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:

    • Given different scenarios benefit from different parameters, it's good to allow customization.
      • For smart, mostly accurate and helpful GlaDOS turn temperature and various other parameters down. Turn them up if you want more witty jokes and creativity at risk of dreaming up stuff.
    • Ability to use one LLM server for multiple tasks (GlaDOS, Coding, ST and RAG) when each client sends their sampling parameters along with each request.
  • Testing/Edge cases

    • When user comments out all the parameters, the (llama.cpp ¹ ) safe defaults from class LlamaGenConfig are used, preventing any errors.
      • Although this could've been an if statement, in edge cases like the server being configured for coding tasks by default, it's better to use the safe defaults from this.
  • TODOs

    • Implement some of the less-important sampling parameters. I've decided not to do it since the defaults are usually best there, although some people might want repetition penalty for long conversations..?
  • Notes

    • llama.cpp safe defaults ¹ Since LLama.cpp defaults differ between their API descriptions and readme descriptions, I've opted to use the default values from llama.cpp's chat UI (while running LLama3.1 8b)

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration class, LlamaGenConfig, enhancing the control over Llama generation parameters.
    • Added a YAML configuration section allowing users to customize Llama generation settings.
  • Improvements

    • Enhanced the Glados class to support new parameters for improved Llama generation.
    • Updated the main execution flow to load configurations from YAML for dynamic adjustments.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

The recent changes introduce a new data class, LlamaGenConfig, to encapsulate parameters related to the Llama generation model in the Glados framework. This addition includes methods for loading configurations from a YAML file and enhances the Glados class constructor to accept these new parameters. The process_LLM method is updated to include the Llama generation parameters when communicating with the LLM server, improving the model's operational capabilities.

Changes

Files Change Summary
glados.py Added LlamaGenConfig class and from_yaml method; modified Glados constructor and from_config method to integrate new Llama generation parameters.
glados_config.yml Introduced a new configuration section LlamaGenConfig with parameters (temperature, dynatemp_range, etc.) for model behavior customization.

Poem

🐇 In fields of code where rabbits play,
New settings bloom, bright as day.
LlamaGenConfig hops along,
With tweaks and turns, we'll sing our song!
Flexibility in each new line,
A dance of data, all divine! 🌼


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 Status

The default values for LlamaGenConfig parameters in glados_config.yml have some context indicating a recommended temperature setting. However, a TODO comment suggests that parameters from min_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 of min_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, and min_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 txt

Length of output: 523

glados.py (1)

48-54: Inconsistency in temperature default value between code and configuration

The temperature parameter in the LlamaGenConfig class has a default value of 0.7, while the glados_config.yml specifies 0.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 in glados_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 cat

Length 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 cat

Length of output: 2889

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 99fbf5e and 6bc2bb3.

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, and min_p are properly initialized and used within the glados.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 ""
done

Length 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 10

Length of output: 1388


Line range hint 204-226:
Verify integration of LlamaGenConfig parameters.

Ensure that the integration of LlamaGenConfig parameters in the from_config method is consistent and correctly implemented.

Comment on lines +56 to +60
@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)
Copy link
Contributor

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)

Comment on lines +162 to +166
#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
Copy link
Contributor

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

@dnhkng
Copy link
Owner

dnhkng commented Aug 14, 2024

Much appreciated!

I will be leaving today for an overseas holiday, I can review this when I'm back next month.

@Skyrion9
Copy link
Contributor Author

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!

@dnhkng
Copy link
Owner

dnhkng commented Jan 3, 2025

@Skyrion9 I've done a big refactor, could you reintegrate your changes?

@Skyrion9
Copy link
Contributor Author

Skyrion9 commented Jan 4, 2025

@Skyrion9 I've done a big refactor, could you reintegrate your changes?

I'll have a look after Sunday

@Skyrion9 Skyrion9 force-pushed the GlaDOS_SamplingConfig branch from 6bc2bb3 to f74ac90 Compare January 7, 2025 00:09
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 payload

When constructing the data dictionary for the LLM server, if any generation parameter is None, it could cause issues with the server if it doesn't handle None 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 parameters

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6bc2bb3 and f74ac90.

📒 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 in from_yaml method

The 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 parameters

To 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 needed
glados_config.yml (1)

23-28: Ensure consistency between default values in code and configuration

The temperature parameter in the configuration file is set to 0.1, while the default value in the code is 0.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.

glados.py Outdated Show resolved Hide resolved
Comment on lines +100 to +105
temperature = float,
dynatemp_range = float,
dynatemp_exponent = float,
top_k = int,
top_p = float,
min_p = float,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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>
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 to from_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

📥 Commits

Reviewing files that changed from the base of the PR and between f74ac90 and edae7a8.

📒 Files selected for processing (1)
  • glados.py (7 hunks)
🔇 Additional comments (4)
glados.py (4)

53-60: Add error handling in from_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 suggestion

Add 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 to from_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

📥 Commits

Reviewing files that changed from the base of the PR and between f74ac90 and edae7a8.

📒 Files selected for processing (1)
  • glados.py (7 hunks)
🔇 Additional comments (4)
glados.py (4)

53-60: Add error handling in from_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 suggestion

Add 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.

@Skyrion9
Copy link
Contributor Author

Skyrion9 commented Jan 7, 2025

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.

@dnhkng
Copy link
Owner

dnhkng commented Jan 7, 2025

@Skyrion9 thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants