1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # build-system 8 cmake, 9 ninja, 10 pybind11, 11 scikit-build-core, 12 13 # dependencies 14 pydantic, 15 sentencepiece, 16 tiktoken, 17 torch, 18 transformers, 19 triton, 20 21 # tests 22 pytestCheckHook, 23 writableTmpDirAsHomeHook, 24}: 25 26buildPythonPackage rec { 27 pname = "xgrammar"; 28 version = "0.1.14"; 29 pyproject = true; 30 31 src = fetchFromGitHub { 32 owner = "mlc-ai"; 33 repo = "xgrammar"; 34 tag = "v${version}"; 35 fetchSubmodules = true; 36 hash = "sha256-ohsoc3g5XUp9vSXxyOGj20wXzCXZC02ktHYVQjDqNeM="; 37 }; 38 39 build-system = [ 40 cmake 41 ninja 42 pybind11 43 scikit-build-core 44 ]; 45 dontUseCmakeConfigure = true; 46 47 dependencies = 48 [ 49 pydantic 50 sentencepiece 51 tiktoken 52 torch 53 transformers 54 ] 55 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64) [ 56 triton 57 ]; 58 59 nativeCheckInputs = [ 60 pytestCheckHook 61 writableTmpDirAsHomeHook 62 ]; 63 64 disabledTests = [ 65 # You are trying to access a gated repo. 66 "test_grammar_compiler" 67 "test_grammar_matcher" 68 "test_grammar_matcher_ebnf" 69 "test_grammar_matcher_json" 70 "test_grammar_matcher_json_schema" 71 "test_grammar_matcher_tag_dispatch" 72 "test_regex_converter" 73 "test_tokenizer_info" 74 75 # Torch not compiled with CUDA enabled 76 "test_token_bitmask_operations" 77 78 # AssertionError 79 "test_json_schema_converter" 80 ]; 81 82 pythonImportsCheck = [ "xgrammar" ]; 83 84 meta = { 85 description = "Efficient, Flexible and Portable Structured Generation"; 86 homepage = "https://xgrammar.mlc.ai"; 87 changelog = "https://github.com/mlc-ai/xgrammar/releases/tag/v${version}"; 88 license = lib.licenses.asl20; 89 }; 90}