How hkust-zhiyao/rtl-coder works
Main Components
• Data Generation Module:
– Folders: “data_generation” and “dataset”
– Purpose: Automates creating a labeled dataset of design instructions and reference Verilog code. Includes prompt templates (p_example.txt), utilities, and sample data (e.g., Resyn27k.json).
• Inference/Benchmarking Module:
– Folder: “benchmark_inference”
– Purpose: Provides scripts for testing generated RTL code using various benchmarks (RTLLM and Verilog-eval) and for different model variants (RTLCoder-Deepseek, RTLCoder-v1.1, quantized 4-bit versions, etc.).
• Training Module:
– Folder: “train”
– Purpose: Contains scripts for multiple training strategies, including standard Maximum Likelihood Estimation (MLE) training and new LLM training schemes based on code quality scoring. Includes gradient splitting for memory efficiency.
• Supporting Components & Resources:
– “requirements.txt” for dependency management
– “README.md” and “_pic” (images for data generation and training flows) to document system flows and citation/paper references
Relationships and Interactions
• The Data Generation module feeds into both Training (providing the large labeled dataset) and benchmarking (if generating new test cases).
• The trained LLM models are then used in the Inference module to generate RTL code when provided with a prompt.
• The Inference scripts have different flows based on the model variant (e.g., Deepseek, GPTQ-4bit) and include special post-processing steps (like handling the “endmodule” token).
• There is a feedback loop in the training methodology which incorporates code quality scoring into the model training, as depicted in the training flow in the README.
Architectural Patterns & Technologies
• Modular design: The project clearly divides responsibilities among data generation, benchmarking, and training.
• Pipeline flow: Each module demonstrates a sequential or “stage‐based” flow (e.g., data generation stages described in Figure 1 and training scheme in Figure 2).
• Integration with external packages: For inference, the project leverages external packages like ctransformers and HuggingFace Transformers to load and run the models.
• GPU/CPU considerations: Handling inference on different hardware (e.g. using GPU for standard models or CPU for the gguf quantized version).
– “Data Generation Module” that outputs to both “Dataset Repository” and gets consumed during Training.
– “Training Module” that uses the dataset to fine-tune various LLM models (list the four model variants).
– “Inference/Benchmarking Module” that includes scripts such as “test_on_rtllm.py” and “test_on_verilog-eval.py” along with pre-/post-processing blocks.
• Use notes or side annotations to indicate the use of external libraries (HuggingFace Transformers, ctransformers, deepspeed) and important configurations (GPU memory optimizations, use of quantization).
• Every component (folder/problem domain) is represented, even if briefly—this helps capture the entire project’s scope.