Unverified Commit 4697d9df authored by Nick Cao's avatar Nick Cao Committed by GitHub
Browse files

python312Packages.xgrammar: 0.1.11 -> 0.1.14 (#386255)

parents 3996a40a 92250720
Loading
Loading
Loading
Loading
+37 −40
Original line number Diff line number Diff line
@@ -3,57 +3,63 @@
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  cmake,
  ninja,
  pip,
  pytestCheckHook,
  python3,
  pybind11,
  scikit-build-core,

  # dependencies
  pydantic,
  sentencepiece,
  tiktoken,
  torch,
  transformers,
  triton,

  # tests
  pytestCheckHook,
  writableTmpDirAsHomeHook,
}:

buildPythonPackage rec {
  pname = "xgrammar";
  version = "0.1.11";
  format = "other";
  version = "0.1.14";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "mlc-ai";
    repo = pname;
    repo = "xgrammar";
    tag = "v${version}";
    hash = "sha256-q5d8/9S9p9M8HlCIernT9IwPEDnbC1R9nGsLuS15RXY=";
    fetchSubmodules = true;
    hash = "sha256-ohsoc3g5XUp9vSXxyOGj20wXzCXZC02ktHYVQjDqNeM=";
  };

  nativeBuildInputs = [
  build-system = [
    cmake
    ninja
    pybind11
    scikit-build-core
  ];
  dontUseCmakeConfigure = true;

  buildInputs = [ pip ];

  dontUseNinjaInstall = true;

  installPhase = ''
    runHook preInstall

    cd ../python
    ${python3.interpreter} -m pip install --prefix=$out .
    cd ..

    runHook postInstall
  '';

  nativeCheckInputs = [ pytestCheckHook ];
  dependencies =
    [
      pydantic
      sentencepiece
      tiktoken
      torch
      transformers
    ]
    ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64) [
      triton
    ];

  preCheck = ''
    cd tests/python/
  '';
  nativeCheckInputs = [
    pytestCheckHook
    writableTmpDirAsHomeHook
  ];

  disabledTests = [
    # You are trying to access a gated repo.
@@ -64,27 +70,18 @@ buildPythonPackage rec {
    "test_grammar_matcher_json_schema"
    "test_grammar_matcher_tag_dispatch"
    "test_regex_converter"
    "test_tokenizer_info"

    # Torch not compiled with CUDA enabled
    "test_token_bitmask_operations"
    # You are trying to access a gated repo.
    "test_tokenizer_info"
  ];

  pythonImportsCheck = [ "xgrammar" ];

  dependencies = [
    pybind11
    pydantic
    sentencepiece
    tiktoken
    torch
    transformers
    triton
  ];

  meta = with lib; {
  meta = {
    description = "Efficient, Flexible and Portable Structured Generation";
    homepage = "https://xgrammar.mlc.ai";
    license = licenses.asl20;
    changelog = "https://github.com/mlc-ai/xgrammar/releases/tag/v${version}";
    license = lib.licenses.asl20;
  };
}