-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: Enhance prompt formatting and optimize model performance #41
Conversation
- Introduced a new prompt template for more consistent and helpful responses. - Updated the `generate_complaint` function to use the new prompt format. - Adjusted batch sizes and gradient accumulation steps for better VRAM utilization on WSL2. - Added debug prints for formatted prompts and tokenized inputs to aid in troubleshooting. - Removed unnecessary HF_TOKEN usage in model and tokenizer initialization. - Implemented a method to clear model caches before running benchmarks to optimize memory usage. - Extended output character limit in benchmark sample outputs for more comprehensive analysis.
Reviewer's Guide by SourceryThis PR enhances the model's prompt formatting and optimizes performance through several key changes. The implementation introduces a standardized prompt template across different modules, adjusts training parameters for better VRAM utilization, adds debugging capabilities, and implements memory optimization techniques. The changes primarily focus on improving model interaction consistency and resource efficiency. Sequence diagram for prompt formatting in inferencesequenceDiagram
participant User
participant System
participant Model
participant Tokenizer
User->>System: Provide instruction
System->>Model: format_prompt(instruction)
Model->>System: Formatted Prompt
System->>Tokenizer: Tokenize Formatted Prompt
Tokenizer->>System: Tokenized Input IDs
System->>Model: Generate response
Model->>System: Raw Output IDs
System->>Tokenizer: Decode Output IDs
Tokenizer->>System: Decoded Response
System->>User: Provide response
Updated class diagram for prompt formatting and model interactionclassDiagram
class FineTuning {
+format_prompt(instruction: str, response: str) str
+inference_example(model, tokenizer, prompt: str) str
}
class Benchmark {
+generate_response(prompt: str) str
+clear_model_caches() void
+run_benchmark(num_samples: int) Dict[str, Any]
}
class FineTuneTest {
+generate_complaint(prompt: str) str
}
note for FineTuning "Updated prompt formatting method"
note for Benchmark "Added cache clearing method"
note for FineTuneTest "Updated prompt template and instruction"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider making the date in the prompt template dynamic rather than hardcoding '23 July 2024' to ensure the system remains current over time.
- The change from specific complaint-focused instructions to generic 'Tell me about' prompts may affect the model's response style. Was this intentional? If so, please document the reasoning.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -156,8 +157,21 @@ def filter_quality(example: Dict[str, Any]) -> bool: | |||
return special_char_ratio <= 0.2 | |||
|
|||
|
|||
def format_prompt(instruction: str, response: str = "") -> str: |
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.
issue (complexity): Consider consolidating the duplicate format_prompt functions into a single implementation
The duplicate format_prompt
functions with slightly different implementations introduce unnecessary complexity and potential for bugs. Consolidate them into a single function:
def format_prompt(instruction: str, response: str = "") -> str:
"""Format the prompt for the model with consistent system context and structure."""
return f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
Cutting Knowledge Date: December 2023
Today Date: 23 July 2024
You are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>
{instruction}<|eot_id|><|start_header_id|>assistant<|end_header_id|>
{response}<|eot_id|>"""
This consolidation:
- Uses consistent dates rather than mixing hardcoded and dynamic dates
- Maintains a single prompt template structure
- Removes the risk of diverging implementations
- Preserves all functionality while reducing code duplication
generate_complaint
function to use the new prompt format.Summary by Sourcery
Enhance prompt formatting for improved model responses and optimize model performance by adjusting batch sizes, clearing caches, and extending output limits in benchmarks.
New Features:
Enhancements: