量子化(INT8)版 swan_q のビルドとKV260での実行 - takgto/utokyo-chipathon2023 GitHub Wiki
量子化(重み係数、計算の一部)を行う場合の手順です。
1. 必要パッケージの準備
まずはTAに必要パッケージ(swan_q_packages)をDownloadsフォルダにコピーしてもらいます。
/Users/x-nics-kuroda/Downloads/swan_q_packages
2. Vitis applicationの立ち上げとビルド
Vitisで新規project名(swan_q_testなど)でVitis applicationを立ち上げた後は、前ページのswanと同じやり方で、kernelのビルドとcpuのビルドを行い、新しいbinary_container_1.xclbin と swan_q を得ます。platformとsysrootは前ページのswanと同じ指定でよいです。ソースファイルは次からimportします。
Kernel filesのimport
以降、application project nameをswan_qとしたと仮定します。
/Users/x-nics-kuroda/Downloads/swan_q_packages/src_fpga/*.cpp(6 files) → swan_q_kernels/src
ビルド後、~/<project name>/swan_q_system_hw_link/Hardware/binary_container_1.xclbin ができます。
CPU filesのimport
/Users/x-nics-kuroda/Downloads/swan_q_packages/src_cpu/*.cpp, *.hpp(11 files) → swan_q/src
ビルド後、~/<project name>/swan_q/Hardware/swan_q ができます。
3. KV260への転送
binary_container_swan_q.xclbin という名前で /home/root に転送します。
scp ~/<project name>/swan_q_system_hw_link/Hardware/binary_container_1.xclbin [email protected]:/home/root/binary_container_swan_q.xclbin
cpu側の実行ファイル(swan_q)をKV260のhome directory(/home/root)に転送します。
scp ~/<project name>/swan_q/Hardware/swan_q [email protected]:/home/root
/Users/x-nics-kuroda/Downloads/swan_q_packages において次を実行すると、量子化モデルが以下のようにKV260に転送されます。
./deploy_models.sh
KV260 directory structure:
/home/root/
├── model/
│ └── tokenizer.bin
├── quantized/
│ ├── model_quantized.bin (original)
│ └── quantize_metadata.bin (original)
└── quantized_instruct/
├── model_quantized.bin (instruct)
└── quantize_metadata.bin (instruct)
4. KV260での作業(MobaXtermで)
binary_container_1.bin にリンクを張ります。
ln -sf binary_container_swan_q.xclbin binary_container_1.bin
ls -la binary_container_1.bin
次のようになっていればOKです。
lrwxrwxrwx 1 root 30 Jun 11 02:39 binary_container_1.bin -> binary_container_swan_q.xclbin
5. swan_q環境の作成
/lib/firmware/xilinx/ に swan_q の環境を作ります。
cd /lib/firmware/xilinx
mkdir -p swan_q
cd swan_q
cp ../swan/shell.json .
cp ../swan/swan.dtbo swan_q.dtbo
ln -sf /home/root/binary_container_1.bin swan_q.bit.bin
ln -sf /home/root/binary_container_1.bin swan_q.xclbin
xmutil unloadapp && xmutil loadapp swan_q
xmutil listapps で swan_q のActive slotのみが 0 になっていればOKです。
xmutil listapps
xmutil listapps の結果例:
Accelerator Accel_type Base Base_type #slots(PL+AIE) Active_slot
swan XRT_FLAT swan XRT_FLAT (0+0) -1
kv260-benchmark-b4096 XRT_FLAT kv260-benchmark-b4096 XRT_FLAT (0+0) -1
swan_q_v7 XRT_FLAT swan_q_v7 XRT_FLAT (0+0) -1
k26-starter-kits XRT_FLAT k26-starter-kits XRT_FLAT (0+0) -1
swan_q_v4 XRT_FLAT swan_q_v4 XRT_FLAT (0+0) -1
swan_q_instruct XRT_FLAT swan_q_instruct XRT_FLAT (0+0) -1
swan_q XRT_FLAT swan_q XRT_FLAT (0+0) 0,
6. 実行方法
実行する時はMobaXtermならSSHターミナルを使うこと(文字化けを防ぐため)。
Free story版
./swan_q --no-prompt
Instruction版
単語を2語入力すると、その2語を使ったStoryを出力します。
./swan_q --weight_path ./quantized_instruct/model_quantized.bin --params_path ./quantized_instruct/quantize_metadata.bin --prompt
Instruction版の例
Instruction: と聞いてくるので、Write a story using the words: sunshine, boy を入力します。この場合、keywordsは sunshine, boy で自由の単語の組み合わせが入力可能です。これら単語は関連性のある一連の単語を入力してください(3語までOK)。全く関係の無い単語を2語3語と選んだとしても1語しかStoryには使われないと思ってください。
15MBのモデルですので、関連性のある2語を指定したとしても両方ともStoryに使われない場合もあります。
Instruction: Write a story using the words: sunshine, boy
--- Story ---
3 years years, a boy named Tom was walking through the park with his dad. Tom was a curious boy who loved playing in the sunshine. Today, he was so excited to go for a walk by himself.
Suddenly, he heard a voice behind him. Tom turned and looked around, but he couldn't see anyone. He walked forward to the ground, and then he saw a friendly dog. Tom was wagging his tail was a friendly face, and he wagged his tail up and down, and then he heard the friendly voice from behind the trees, "ältorant!"
Tom turned and saw a little boy, and then he turned and saw a friendly dog. Tom was very curiously approached the dog.
Tom asked, "eradeible. Is it a friendly dog, and this time, he was wagging his tail up close.
Tom was surprised, and he said, ")",i's eyes lit up, and he started to purr. " bandei, you can hardly believe it!"
complexi was amazed, and he started to purr, and then brav
--- Statistics ---
Time : 46.1936[s]
Speed: 5.5419[tok/s]