
- บล็อก | เอกสาร หย่อน | ฟอรัมสนทนา |
FlashInfer เป็นเครื่องกำเนิดห้องสมุดและเคอร์เนลสำหรับรุ่นภาษาขนาดใหญ่ที่ให้การใช้งานที่มีประสิทธิภาพสูงของเมล็ด GPU LLM เช่น Flashattention, Sparsittention, Pageattention, การสุ่มตัวอย่างและอื่น ๆ FlashInfer มุ่งเน้นไปที่การให้บริการ LLM และการอนุมานและมอบประสิทธิภาพที่ล้ำสมัยในสถานการณ์ที่หลากหลาย
ตรวจสอบบล็อกการเปิดตัว V0.2 ของเราสำหรับคุณสมบัติใหม่!
คุณสมบัติหลักของ FlashInfer ได้แก่ :
plan / run ขั้นตอนของการคำนวณความสนใจซึ่งเรากำหนดเวลาการคำนวณอินพุตความยาวตัวแปรในขั้นตอน plan เพื่อบรรเทาปัญหาการโหลดความสมดุลFlashInfer รองรับ Pytorch, TVM และ C ++ (ส่วนหัวเท่านั้น) APIs และสามารถรวมเข้ากับโครงการที่มีอยู่ได้อย่างง่ายดาย
การใช้ Pytorch API ของเราเป็นวิธีที่ง่ายที่สุดในการเริ่มต้น:
เราให้บริการล้อ prebuilt สำหรับ linux คุณสามารถติดตั้ง FlashInfer ด้วยคำสั่งต่อไปนี้:
# For CUDA 12.4 & torch 2.4
pip install flashinfer -i https://flashinfer.ai/whl/cu124/torch2.4
# For other CUDA & torch versions, please check https://docs.flashinfer.ai/installation.htmlนอกจากนี้เรายังนำเสนอล้อที่สร้างขึ้นทุกคืนเพื่อลองคุณสมบัติล่าสุดจากสาขาหลัก:
pip install flashinfer -i https://flashinfer.ai/whl/nightly/cu124/torch2.4หรือคุณสามารถสร้าง flashinfer จากแหล่งที่มา:
git clone https://github.com/flashinfer-ai/flashinfer.git --recursive
cd flashinfer
pip install -e . -v โดยค่าเริ่มต้น FlashInfer ใช้การรวบรวมแบบทันเวลา (JIT) สำหรับเคอร์เนล หากต้องการทำการควบคุมเมล็ดพันธุ์ที่จำเป็นล่วงหน้าให้ตั้งค่าตัวแปรสภาพแวดล้อม FLASHINFER_ENABLE_AOT=1 ก่อนเรียกใช้คำสั่งการติดตั้ง:
FLASHINFER_ENABLE_AOT=1 pip install -e . -vสำหรับรายละเอียดเพิ่มเติมโปรดดูที่การติดตั้งจากเอกสารต้นฉบับ
ด้านล่างนี้เป็นตัวอย่างที่น้อยที่สุดของการใช้เคอร์เนลการถอดรหัส/เสริม/เสริม/prefill ความสนใจของ FlashInfer:
import torch
import flashinfer
kv_len = 2048
num_kv_heads = 32
head_dim = 128
k = torch . randn ( kv_len , num_kv_heads , head_dim ). half (). to ( 0 )
v = torch . randn ( kv_len , num_kv_heads , head_dim ). half (). to ( 0 )
# decode attention
num_qo_heads = 32
q = torch . randn ( num_qo_heads , head_dim ). half (). to ( 0 )
o = flashinfer . single_decode_with_kv_cache ( q , k , v ) # decode attention without RoPE on-the-fly
o_rope_on_the_fly = flashinfer . single_decode_with_kv_cache ( q , k , v , pos_encoding_mode = "ROPE_LLAMA" ) # decode with LLaMA style RoPE on-the-fly
# append attention
append_qo_len = 128
q = torch . randn ( append_qo_len , num_qo_heads , head_dim ). half (). to ( 0 ) # append attention, the last 128 tokens in the KV-Cache are the new tokens
o = flashinfer . single_prefill_with_kv_cache ( q , k , v , causal = True ) # append attention without RoPE on-the-fly, apply causal mask
o_rope_on_the_fly = flashinfer . single_prefill_with_kv_cache ( q , k , v , causal = True , pos_encoding_mode = "ROPE_LLAMA" ) # append attention with LLaMA style RoPE on-the-fly, apply causal mask
# prefill attention
qo_len = 2048
q = torch . randn ( qo_len , num_qo_heads , head_dim ). half (). to ( 0 ) # prefill attention
o = flashinfer . single_prefill_with_kv_cache ( q , k , v , causal = False ) # prefill attention without RoPE on-the-fly, do not apply causal maskตรวจสอบเอกสารประกอบสำหรับการใช้งานชุด DECODE/APPEND/PREFILL KERNES และเมล็ดที่ใช้ร่วมกัน
เราโปรไฟล์ประสิทธิภาพเคอร์เนล FlashInfer ด้วย NVBench และคุณสามารถรวบรวมและเรียกใช้มาตรฐานด้วยคำสั่งต่อไปนี้:
mkdir build
cp cmake/config.cmake build # you can modify the config.cmake to enable/disable benchmarks and change CUDA architectures
cd build
cmake ..
make -j12 คุณสามารถเรียกใช้ ./bench_{single/batch}_{prefill/decode} เพื่อเปรียบเทียบประสิทธิภาพ (เช่น ./bench_single_prefill bench_single_prefill สำหรับความสนใจแบบล่วงหน้า ./bench_{single/batch}_{prefill/decode} --help จะแสดงตัวเลือกที่มีอยู่ให้คุณ
FlashInfer ยังมีการผูก C ++ API และ TVM โปรดดูเอกสารสำหรับรายละเอียดเพิ่มเติม
เราตื่นเต้นที่จะแบ่งปันว่า FlashInfer กำลังถูกนำมาใช้โดยโครงการที่ทันสมัยหลายโครงการรวมถึง แต่ไม่ จำกัด เพียง:
FlashInfer ได้รับแรงบันดาลใจจาก Flashattention 1 & 2, VLLM, Stream-K, Cutlass และ Aitemplate Project