151 lines
4.8 KiB
Markdown
151 lines
4.8 KiB
Markdown
---
|
|
license: apache-2.0
|
|
pipeline_tag: text-generation
|
|
tags:
|
|
- chat
|
|
- llm
|
|
- safetensors
|
|
base_model: Qwen/Qwen2.5-14B-Instruct
|
|
language:
|
|
- en
|
|
---
|
|
|
|
# ChatHLS-HLSFixer
|
|
|
|
## Model Details
|
|
|
|
- **Finetuned from model:** `Qwen/Qwen2.5-14B-Instruct`
|
|
- **Model source paper:** [ChatHLS: Towards Systematic Design Automation and Optimization for High-Level Synthesis](https://arxiv.org/abs/2507.00642)
|
|
- **Project repository:** [GEAR-SEU/ChatHLS-ACL-26](https://github.com/GEAR-SEU/ChatHLS-ACL-26)
|
|
|
|
## Description
|
|
|
|
**ChatHLS-HLSFixer** is a specialized Large Language Model fine-tuned for High-Level Synthesis (HLS) C/C++ error correction. It acts as the core analysis agent within the ChatHLS framework.
|
|
|
|
## Quickstart
|
|
|
|
### Prerequisites
|
|
```bash
|
|
pip install transformers torch accelerate
|
|
```
|
|
|
|
### Example
|
|
|
|
Here is a simple example of how to format your prompt and generate debugging instructions for buggy HLS code:
|
|
|
|
````python
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
import torch
|
|
|
|
model_name = "XXXiong/ChatHLS-HLSFixer"
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|
model_name,
|
|
torch_dtype=torch.bfloat16,
|
|
device_map="auto"
|
|
)
|
|
|
|
buggy_code = """
|
|
#include "ap_fixed.h"
|
|
void vector_mul(ap_fixed<32,16> a[8], ap_fixed<32,16> b[8], ap_fixed<32,16> c[8]) {
|
|
#pragma HLS ARRAY_PARTITION variable=a complete dim=1
|
|
#pragma HLS ARRAY_PARTITION variable=b complete dim=1
|
|
#pragma HLS ARRAY_PARTITION variable=c complete dim=1
|
|
for (int i = 0; i < 8; ++i) {
|
|
#pragma HLS UNROLL
|
|
#pragma HLS PIPELINE II=1
|
|
c[i] = a[i] * b[i];
|
|
}
|
|
}
|
|
"""
|
|
|
|
error_log = """
|
|
"ERROR: [HLS 214-274] In 'VITIS_LOOP_7_1', Pragma conflict happens on 'UNROLL' and 'PIPELINE' pragmas: Complete unroll will break the target of other loop pragmas (vector_mul.cpp:7:18)",
|
|
"ERROR: [HLS 200-1715] Encountered problem during source synthesis"
|
|
"""
|
|
|
|
prompt = f"""You are given a piece of HLS code that contains bugs, the compiler error log, and the description of the buggy code.
|
|
Your task is to debug the buggy code by analyzing the differences between it and the original code, using the error log to guide you.
|
|
Generate the COT debugging strategy through the buggy code, the code's description and error log.
|
|
|
|
**Instructions:**
|
|
|
|
1. **Debug the Code**:
|
|
- **Identify Errors**: List the erroneous code line in the buggy code.
|
|
- **Analyze Reasons**: Explain why each bug occurred, referencing the error log and the differences from the original code.
|
|
- **Propose Fixes**: Specify the exact changes needed to fix each bug, including code modifications.
|
|
|
|
2. **Construct a Chain of Thought (CoT)**:
|
|
- **Sequential Reasoning**: Address one error at a time, starting with syntax errors from the compiler.
|
|
- **Hypothesis Formation**: Hypothesize why logical errors occur based on the error log and code comparison.
|
|
- **Testing and Verification**: Validate hypotheses through analysis.
|
|
- **Reflection**: Reflect on the findings after each step and plan the next steps.
|
|
|
|
3. **Output**:
|
|
- **Chain of Thought (CoT)**: Write a detailed explanation of your debugging process.
|
|
- **Bug Analysis in JSON Format**: Provide a structured summary as per the format below.
|
|
- **No other explanations or conclusions**
|
|
|
|
**Inputs:**
|
|
|
|
Buggy Code:
|
|
```cpp
|
|
{buggy_code}
|
|
```
|
|
|
|
Vitis HLS Compiler Error Log:
|
|
```text
|
|
{error_log}
|
|
```
|
|
|
|
**Expected Output Format:**
|
|
|
|
Bug Analysis:
|
|
```json
|
|
{{
|
|
"bug_analysis": [
|
|
{{
|
|
"erroneous_code_line": "[code line]",
|
|
"reason": "[Explanation of why the bug occurred]",
|
|
"modification_actions": [
|
|
{{
|
|
"action": "[Specific modification to be made]",
|
|
"reason": "[Reason for the modification]"
|
|
}}
|
|
]
|
|
}}
|
|
]
|
|
}}
|
|
```
|
|
Please ensure that the JSON is properly formatted and valid.
|
|
"""
|
|
|
|
messages = [
|
|
{"role": "system",
|
|
"content": """You are an expert in High-Level Synthesis (HLS) programming.
|
|
Your primary task is to identify and debug HLS-incompatible errors in regular C/C++ programs. You will be provided with:
|
|
- **Buggy Code**: A C/C++ program containing HLS-incompatible errors.
|
|
- **Compiler Error Log**: The error messages generated by the Vitis HLS compiler."""},
|
|
{"role": "user", "content": prompt}
|
|
]
|
|
|
|
text = tokenizer.apply_chat_template(
|
|
messages,
|
|
tokenize=False,
|
|
add_generation_prompt=True
|
|
)
|
|
|
|
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
|
|
|
generated_ids = model.generate(
|
|
**model_inputs,
|
|
max_new_tokens=2048,
|
|
temperature=0.7
|
|
)
|
|
generated_ids = [
|
|
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
|
]
|
|
|
|
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
print(response)
|
|
```` |