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 # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("replicate/flashinfer-draft", version=1) - Notebooks
- Google Colab
- Kaggle
Download include/flashinfer/gemm/fp4_gemm_cutlass.h from replicate/flashinfer-draft: direct link, hf CLI and curl.
- Browser
- Download file 3.25 kB
-
https://huggingface.co/replicate/flashinfer-draft/resolve/main/include/flashinfer/gemm/fp4_gemm_cutlass.h
- Command line
-
hf download hf://replicate/flashinfer-draft/include/flashinfer/gemm/fp4_gemm_cutlass.h
-
curl -L -o fp4_gemm_cutlass.h https://huggingface.co/replicate/flashinfer-draft/resolve/main/include/flashinfer/gemm/fp4_gemm_cutlass.h
3.25 kB
| /* | |
| * SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights | |
| * reserved. SPDX-License-Identifier: Apache-2.0 | |
| * | |
| * 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 { | |
| namespace gemm { | |
| /* | |
| This runner supports: | |
| FP4 inputs (A and B) | |
| float blockwise scaling factor | |
| float alpha scalings | |
| T output (D) where T = {float, half, __nv_bfloat16} | |
| Activations, biases and outputs are all assumed to be row-major. | |
| Weights are assumed to be column-major. | |
| Block scaling factor are interleaved. | |
| */ | |
| class CutlassFp4GemmRunnerInterface { | |
| public: | |
| CutlassFp4GemmRunnerInterface() {} | |
| virtual ~CutlassFp4GemmRunnerInterface() {} | |
| virtual void gemm(void* D, void const* A, void const* B, void const* input_sf, | |
| void const* weight_sf, float const* global_sf, int m, int n, int k, | |
| int batch_count, CutlassGemmConfig gemmConfig, char* workspace, | |
| const size_t workspaceBytes, cudaStream_t stream) = 0; | |
| // Returns desired workspace size in bytes. | |
| virtual size_t getWorkspaceSize(int const m, int const n, int const k, int batch_count) = 0; | |
| virtual std::vector<CutlassGemmConfig> getConfigs() const = 0; | |
| }; | |
| enum class FP4GemmType { | |
| W4A4_NVFP4_NVFP4, | |
| }; | |
| template <typename T, FP4GemmType gemmType = FP4GemmType::W4A4_NVFP4_NVFP4> | |
| class CutlassFp4GemmRunner : public virtual CutlassFp4GemmRunnerInterface { | |
| public: | |
| CutlassFp4GemmRunner(); | |
| ~CutlassFp4GemmRunner(); | |
| void gemm(void* D, void const* A, void const* B, void const* input_sf, void const* weight_sf, | |
| float const* global_sf, int m, int n, int k, int batch_count, | |
| CutlassGemmConfig gemmConfig, char* workspace, const size_t workspaceBytes, | |
| cudaStream_t stream) override; | |
| // Returns desired workspace size in bytes. | |
| size_t getWorkspaceSize(int const m, int const n, int const k, int const batch_count) override; | |
| std::vector<CutlassGemmConfig> getConfigs() const override; | |
| private: | |
| size_t dispatchToArch(T* D, void const* A, void const* B, void const* input_sf, | |
| void const* weight_sf, float const* global_sf, int m, int n, int k, | |
| int batch_count, CutlassGemmConfig gemmConfig, char* workspace, | |
| const size_t workspaceBytes, cudaStream_t stream, int* occupancy = nullptr); | |
| size_t getWorkspaceSizeImpl(int const m, int const n, int const k, int const batch_count); | |
| }; | |
| } // namespace gemm | |
| } // namespace flashinfer | |