Instructions to use replicate/flashinfer-draft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use replicate/flashinfer-draft with Kernels:
# !pip install kernels from kernels import get_kernel kernel = get_kernel("replicate/flashinfer-draft") - Notebooks
- Google Colab
- Kaggle
| /* | |
| * Copyright (c) 2025 by FlashInfer team. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| namespace flashinfer { | |
| __device__ __forceinline__ uint32_t get_block_idx() { | |
| return (blockIdx.z * gridDim.y + blockIdx.y) * gridDim.x + blockIdx.x; | |
| } | |
| __device__ __forceinline__ uint32_t get_num_blocks() { return gridDim.x * gridDim.y * gridDim.z; } | |
| __device__ __forceinline__ uint32_t get_thread_idx() { | |
| return (threadIdx.z * blockDim.y + threadIdx.y) * blockDim.x + threadIdx.x; | |
| } | |
| constexpr uint32_t BLOCK_GROUP_IDX_MASK = 0xFFFFF; | |
| constexpr uint32_t EVENT_IDX_MASK = 0x3FF; | |
| constexpr uint32_t BEGIN_END_MASK = 0x3; | |
| constexpr uint32_t EVENT_IDX_SHIFT = 2; | |
| constexpr uint32_t BLOCK_GROUP_IDX_SHIFT = 12; | |
| constexpr uint32_t SM_ID_SHIFT = 24; | |
| // Tag layout: | |
| // bits 0-1: event_type (start, end, instant) | |
| // bits 2-11: event_idx (translates to event_names in python profiler) | |
| // bits 12-23: block_id (12 bits) | |
| // bits 24-31: sm_id (8 bits) | |
| constexpr uint32_t EVENT_BEGIN = 0x0; | |
| constexpr uint32_t EVENT_END = 0x1; | |
| constexpr uint32_t EVENT_INSTANT = 0x2; | |
| __device__ __forceinline__ uint32_t encode_tag(uint32_t sm_id, uint32_t block_id, | |
| uint32_t event_idx, uint32_t event_type) { | |
| return (sm_id << SM_ID_SHIFT) | (block_id << BLOCK_GROUP_IDX_SHIFT) | | |
| (event_idx << EVENT_IDX_SHIFT) | event_type; | |
| } | |
| __device__ __forceinline__ uint32_t get_timestamp() { | |
| volatile uint32_t ret; | |
| asm volatile("mov.u32 %0, %globaltimer_lo;" : "=r"(ret)); | |
| return ret; | |
| } | |
| struct ProfilerEntry { | |
| union { | |
| struct { | |
| uint32_t nblocks; | |
| uint32_t ngroups; | |
| }; | |
| struct { | |
| uint32_t tag; | |
| uint32_t delta_time; | |
| }; | |
| uint64_t raw; | |
| }; | |
| }; | |
| } // namespace flashinfer | |