자연어만으로는 부족하다: Verilog 생성을 위한 멀티모달 생성 AI 벤치마킹
요약
본 문서는 Verilog 코드 생성을 위한 멀티모달 생성 AI 모델의 성능을 벤치마킹하는 방법을 제시합니다. 산술, 디지털, 고급 회로 등 세 가지 종류의 설계를 포함한 다양한 설계 클래스를 활용하며, 이미지와 상세 설명 같은 복합적인 입력을 통해 모델의 능력을 평가합니다.
핵심 포인트
- Verilog 코드 생성을 위한 멀티모달 AI 벤치마킹 방법론 제시
- 산술/디지털/고급 회로 등 세 가지 난이도의 설계 포함
- 이미지, 상세 설명, 토큰 예측 프롬프트 등 복합 입력 활용
Natural language is not enough: Benchmarking multi-modal generative AI for Verilog generation
Benchmark
benchmark 폴더는 각각 산술 회로(arithmetic circuit), 디지털 회로(digital circuit), 고급 회로(advanced circuit)의 3가지 종류의 설계를 포함합니다. 각 설계 클래스 폴더에는 여러 개의 설계가 있으며, 각 설계는 세 가지 레벨의 설계 설명(simple_design_description.txt: 간단한 설명, medium_design_description.txt: 중간 설명, design_description.txt: 상세 설명)을 포함하고 있습니다. 또한, 각 설계 폴더에는 설계 이미지([design_name].png), 다음 토큰 예측 프롬프트([model_name]_next_token_[idx].txt), 참조 설계 코드(reference.v), 테스트벤치 코드(testbench.v)가 포함되어 있습니다. 전반적으로, 각 설계 폴더는 다음과 같은 파일들을 포함합니다.
-
[design_name].png (설계 이미지)
-
reference.v (설계의 참조 Verilog 코드)
-
testbench.v (설계의 테스트벤치 코드)
-
design_description.txt (멀티모달 모델을 위한 기본/복합 설계 설명)
-
medium_design_description.txt (멀티모달 모델을 위한 중간 설계 설명)
-
simple_design_description.txt (멀티모달 모델을 위한 간단한 설계 설명)
-
gpt4_design_description.txt (자연어 전용 모델을 위한 기본/복합 설계 설명)
-
gpt4_medium_design_description.txt (자연어 전용 모델을 위한 중간 설계 설명)
-
gpt4_simple_design_description.txt (자연어 전용 모델을 위한 간단한 설계 설명)
-
gptv_next_token_1.txt (멀티모달 모델의 토큰 예측 첫 번째 프롬프트)
-
gptv_next_token_2.txt (멀티모달 모델의 토큰 예측 두 번째 프롬프트)
-
gptv_next_token_3.txt (멀티모달 모델의 토큰 예측 세 번째 프롬프트) *주의: 원문에는 1, 2, 1이 반복되어 있으나, 문맥상 3번째가 적절합니다.
-
gpt4_next_token_1.txt (자연어 전용 모델의 토큰 예측 첫 번째 프롬프트)
-
gpt4_next_token_2.txt (자연어 전용 모델의 토큰 예측 두 번째 프롬프트)
-
gpt4_next_token_3.txt (자연어 전용 모델의 토큰 예측 세 번째 프롬프트) *주의: 원문에는 1, 2, 1이 반복되어 있으나, 문맥상 3번째가 적절합니다.
-
code_completion_1.txt (멀티모달 모델의 코드 완성 첫 번째 프롬프트)
-
code_completion_2.txt (멀티모달 모델의 코드 완성 두 번째 프롬프트)
-
code_completion_3.txt (멀티모달 모델의 코드 완성 세 번째 프롬프트)
-
gpt4_code_completion_1.txt (자연어 전용 모델의 코드 완성 첫 번째 프롬프트)
-
gpt4_code_completion_2.txt (자연어 전용 모델의 코드 완성 두 번째 프롬프트)
-
gpt4_code_completion_3.txt (자연어 전용 모델의 코드 완성 세 번째 프롬프트)
환경 설정 (Enviroment establishment)
- 파이썬 환경 설정
pip install requirements.txt
- 테스트 환경을 구축하려면 여기에서
iverilog패키지를 설치해야 합니다. benchmark_exp/llm_generate_code.py,src/llm_complete_code.py,benchmark_exp/llm_predict_token.py파일에 사용자의 OpenAI API 키를 입력하세요. API 제한을 극복하기 위해 2개의 API 키를 사용하는 것을 권장합니다.
코드 실행 방법 (How to run the code)
코드를 실행하려면 다음 명령어를 사용할 수 있습니다.
python benchmark_exp/main.py --model_name=<모델명> --prompt_type=<유형> --method=<방법>
인수(args):
- model_name: gpt-4/gpt-4-vision-preview
- prompt_type: simple/medium/complex (design_descriptions의 세 가지 레벨)
- method: default/complete/predict,
칩 드로(chip draw) 도구에 오신 것을 환영합니다.
당신의 칩 디자인 이름은 무엇인가요?
디자인 이름: <design_name>
...
이 도구를 사용하면 칩 다이어그램을 빠르게 그릴 수 있으며, 서브모듈과 서브모듈 간의 연결만 정의하면 됩니다. 그러면 이 도구가 자동으로 칩 다이어그램을 그려줍니다.
다이어그램에서 코드로: LLM 기반 Verilog 생성을 위한 휴대용 멀티모달 데이터 투영 프레임워크
📚 개요 (Overview)


🔄 멀티모달 데이터 합성 (Multi-Modal Data Synthesis)
폴더: verilog_parse
verilog_parse는 rtlcoder와 같은 기존 데이터셋의 Verilog 코드를 파싱하여 멀티모달 중간 표현(IR)을 생성합니다.
스크립트를 실행하려면 yosys를 설치해야 합니다.
사용법:
python verilog_parse/mmdata_generation.py --input <instruction-verilog-pair-data> --output <multi-modal-intermediate-representation-data>
🔍 프로젝터 (Projector)
폴더: projector
projector는 다이어그램, 테이블, 웨이브(waves)를 읽어 텍스트로 변환합니다. 칩 다이어그램을 처리하기 위해 OCR, 엣지 디텍트(edge detect), 노드 디텍트(node detect)와 같은 전통적인 CV 방법을 사용합니다.
사용법:
python projector/main.py --image_path <image_path>
🔧 파인튜닝 (Finetune)
폴더: finetune
finetune에는 llama3.1과 rtlcoder를 파인튜닝하는 코드가 포함되어 있습니다.
스크립트를 실행하려면 llama-recipes를 설치해야 합니다.
사용법:
데이터_경로(data_path), 모델_경로(model_path) 및 출력_디렉토리(output_dir)에 따라 스크립트를 수정해야 할 수 있습니다.
Llama3.1 파인튜닝 (Finetune Llama3.1)
멀티 GPU에서 파인튜닝
./finetune/train_llama_multigpu.sh
싱글 GPU에서 파인튜닝
./finetune/train_llama_singlegpu.sh
RTLcoder 파인튜닝 (Finetune RTLcoder)
python finetune/train_rtlcoder.py --model_name_or_path <model_name_or_path> --data_path <data_path> --output_dir <output_dir>
📈 DPO (Direct Preference Optimization)
폴더: dpo
dpo는 모델을 추가로 학습시키는 데 사용되는 Direct Preference Optimization (DPO) 코드를 포함하고 있습니다.
사용법: 사용법은 여기를 확인하세요.
📊 평가 (Evaluation)
폴더: benchmark, test_benchmark, verilog_check
benchmark에는 모델 평가를 위한 케이스들이 포함되어 있습니다. 저희는 5가지 유형의 코드를 가지고 있습니다: 산술(arithmetic), 디지털 회로(digital circuit), 유한 상태 기계(fsm), 다중 모듈(multimodule), 테스트벤치(testbench).
test_benchmark에는 모델을 벤치마크에서 테스트하기 위한 코드가 포함되어 있습니다.
verilog_check에는 생성된 verilog 코드를 검사하는 코드가 포함되어 있습니다.
사용 방법:
모델 추론(Model Inference)
llama_ft에 대한 벤치마크
python test_benchmark/llama_finetune_benchmark.py --model_name <model_name> --peft_model <peft_model> --output_dir <output_dir> --use_projector
llama_dpo에 대한 벤치마크
python test_benchmark/dpo_benchmark.py --model_name <model_name> --output_dir <output_dir> --use_projector
rtlcoder에 대한 벤치마크
python test_benchmark/rtlcoder_benchmark.py --model_path <model_path> --output_dir <output_dir> --use_projector
rtlcoder_ft에 대한 벤치마크
python test_benchmark/rtlcoder_finetune_benchmark.py --model <model> --output_dir <output_dir> --use_projector
gpt4에 대한 벤치마크
python test_benchmark/gpt4_benchmark.py --api_key <api_key> --output_dir <output_dir> --use_projector
Verilog 검사(Verilog Check)
폴더: verilog_check
스크립트를 실행하려면 iverilog를 설치해야 합니다.
python verilog_check/code_check.py --generated_code_dir <generated_code_dir>
AI 자동 생성 콘텐츠
본 콘텐츠는 GitHub ML Hardware의 원문을 AI가 자동으로 요약·번역·분석한 것입니다. 원 저작권은 원저작자에게 있으며, 정확한 내용은 반드시 원문을 확인해 주세요.
원문 바로가기