Instructions to use microsoft/Phi-3-small-128k-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/Phi-3-small-128k-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/Phi-3-small-128k-instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-3-small-128k-instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/Phi-3-small-128k-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/Phi-3-small-128k-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-small-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/Phi-3-small-128k-instruct
- SGLang
How to use microsoft/Phi-3-small-128k-instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/Phi-3-small-128k-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-small-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/Phi-3-small-128k-instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/Phi-3-small-128k-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/Phi-3-small-128k-instruct with Docker Model Runner:
docker model run hf.co/microsoft/Phi-3-small-128k-instruct
Fix for FlashAttention RuntimeError & Triton Multi GPU fix.
#17
by Satandon1999 - opened
Files changed (2)
268 unmodified lines269270271272273274275276277278268 unmodified linesreturn (apply_rotary_pos_emb(q, cos_cached[seqlen_offset:seq_len], sin_cached[seqlen_offset:seq_len], seq_dimension=seq_dimension),apply_rotary_pos_emb(k, cos_cached[seqlen_offset:seq_len], sin_cached[seqlen_offset:seq_len], seq_dimension=seq_dimension),)@classmethod268 unmodified lines269270271272273274275276277278268 unmodified linesreturn (apply_rotary_pos_emb(q, cos_cached[seqlen_offset:seq_len], sin_cached[seqlen_offset:seq_len], seq_dimension=seq_dimension).to(q.dtype),apply_rotary_pos_emb(k, cos_cached[seqlen_offset:seq_len], sin_cached[seqlen_offset:seq_len], seq_dimension=seq_dimension).to(q.dtype),)@classmethod
610 unmodified lines611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640350 unmodified lines991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102765 unmodified lines1093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129610 unmodified lines# print(f'> {q.shape=}, {k.shape=}, {layout_crow_indices.shape}, {layout_col_indices.shape}, {layout_crow_indices.stride()}, \# {layout_col_indices.stride()}, {layout_crow_indices=}, {layout_col_indices=}')_fwd_kernel[grid](q, k, v, sm_scale,layout_crow_indices,layout_col_indices,layout_crow_indices.stride(0), layout_crow_indices.stride(1),layout_col_indices.stride(0), layout_col_indices.stride(1),tmp, L, m,o,q.stride(0), q.stride(1), q.stride(2), q.stride(3),k.stride(0), k.stride(1), k.stride(2), k.stride(3),v.stride(0), v.stride(1), v.stride(2), v.stride(3),o.stride(0), o.stride(1), o.stride(2), o.stride(3),q.shape[0], q.shape[1], k.shape[2],k.shape[2] - q.shape[2],q_rounded_len,BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N,BLOCK_DMODEL=BLOCK_DMODEL,EVEN_M_BLOCK=q.shape[2] % BLOCK_M == 0,EVEN_N_BLOCK=k.shape[2] % BLOCK_N == 0 ,INFERENCE=inference,NUM_DBLOCKS=q.shape[-1] // BLOCK_DMODEL,num_warps=num_warps,num_stages=num_stages,)if inference:L, m = None, None350 unmodified linesgrid = (len(q_start_sids), n_heads)_fwd_kernel_batch_inference[grid](q, k, v, out,sm_scale,q_batch_starts,q_batch_ends,k_batch_starts,k_batch_ends,q_batch_ids,q_start_sids,*q.stride(),*k.stride(),*v.stride(),*out.stride(),layout_crow_indices,layout_col_indices,*layout_crow_indices.stride(),*layout_col_indices.stride(),q_k_ratio,HAS_BATCH_DIM = True,D_HEAD = head_size,BLOCK_M = block_size,BLOCK_N = block_size,BLOCK_D = block_d,BLOCK_M_LOADING = 16 if q_len == 1 else block_size, # smaller for decodingEVEN_D = block_d == head_size,num_warps = 1 if q_len == 1 else 4,num_stages = 3)return out65 unmodified linesgrid = (len(q_start_sids), n_heads)_fwd_kernel_batch_inference[grid](q, k, v, out,sm_scale,cu_seqlens_q[:-1],cu_seqlens_q[1:],cu_seqlens_k[:-1],cu_seqlens_k[1:],q_batch_ids,q_start_sids,0, *q.stride(),0, *k.stride(),0, *v.stride(),0, *out.stride(),layout_crow_indices,layout_col_indices,*layout_crow_indices.stride(),*layout_col_indices.stride(),q_k_ratio,HAS_BATCH_DIM = False,D_HEAD = head_size,BLOCK_M = block_size,BLOCK_N = block_size,BLOCK_D = block_d,BLOCK_M_LOADING = 16 if decoding_only else block_size, # smaller for decodingEVEN_D = block_d == head_size,num_warps = 1 if decoding_only else 4,num_stages = 3)return out610 unmodified lines611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641350 unmodified lines99299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102965 unmodified lines10951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132610 unmodified lines# print(f'> {q.shape=}, {k.shape=}, {layout_crow_indices.shape}, {layout_col_indices.shape}, {layout_crow_indices.stride()}, \# {layout_col_indices.stride()}, {layout_crow_indices=}, {layout_col_indices=}')with torch.cuda.device(q.device.index):_fwd_kernel[grid](q, k, v, sm_scale,layout_crow_indices,layout_col_indices,layout_crow_indices.stride(0), layout_crow_indices.stride(1),layout_col_indices.stride(0), layout_col_indices.stride(1),tmp, L, m,o,q.stride(0), q.stride(1), q.stride(2), q.stride(3),k.stride(0), k.stride(1), k.stride(2), k.stride(3),v.stride(0), v.stride(1), v.stride(2), v.stride(3),o.stride(0), o.stride(1), o.stride(2), o.stride(3),q.shape[0], q.shape[1], k.shape[2],k.shape[2] - q.shape[2],q_rounded_len,BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N,BLOCK_DMODEL=BLOCK_DMODEL,EVEN_M_BLOCK=q.shape[2] % BLOCK_M == 0,EVEN_N_BLOCK=k.shape[2] % BLOCK_N == 0 ,INFERENCE=inference,NUM_DBLOCKS=q.shape[-1] // BLOCK_DMODEL,num_warps=num_warps,num_stages=num_stages,)if inference:L, m = None, None350 unmodified linesgrid = (len(q_start_sids), n_heads)with torch.cuda.device(q.device.index):_fwd_kernel_batch_inference[grid](q, k, v, out,sm_scale,q_batch_starts,q_batch_ends,k_batch_starts,k_batch_ends,q_batch_ids,q_start_sids,*q.stride(),*k.stride(),*v.stride(),*out.stride(),layout_crow_indices,layout_col_indices,*layout_crow_indices.stride(),*layout_col_indices.stride(),q_k_ratio,HAS_BATCH_DIM = True,D_HEAD = head_size,BLOCK_M = block_size,BLOCK_N = block_size,BLOCK_D = block_d,BLOCK_M_LOADING = 16 if q_len == 1 else block_size, # smaller for decodingEVEN_D = block_d == head_size,num_warps = 1 if q_len == 1 else 4,num_stages = 3)return out65 unmodified linesgrid = (len(q_start_sids), n_heads)with torch.cuda.device(q.device.index):_fwd_kernel_batch_inference[grid](q, k, v, out,sm_scale,cu_seqlens_q[:-1],cu_seqlens_q[1:],cu_seqlens_k[:-1],cu_seqlens_k[1:],q_batch_ids,q_start_sids,0, *q.stride(),0, *k.stride(),0, *v.stride(),0, *out.stride(),layout_crow_indices,layout_col_indices,*layout_crow_indices.stride(),*layout_col_indices.stride(),q_k_ratio,HAS_BATCH_DIM = False,D_HEAD = head_size,BLOCK_M = block_size,BLOCK_N = block_size,BLOCK_D = block_d,BLOCK_M_LOADING = 16 if decoding_only else block_size, # smaller for decodingEVEN_D = block_d == head_size,num_warps = 1 if decoding_only else 4,num_stages = 3)return out
positional_embedding.py+2-2
triton_flash_blocksparse_attn.py+89-86