1{
2 lib,
3 buildPythonPackage,
4
5 # build-system
6 pybind11,
7 setuptools,
8
9 # dependencies
10 ctranslate2-cpp,
11 numpy,
12 pyyaml,
13
14 # tests
15 pytestCheckHook,
16 tensorflow-bin,
17 torch,
18 transformers,
19 wurlitzer,
20}:
21
22buildPythonPackage rec {
23 inherit (ctranslate2-cpp) pname version src;
24 format = "setuptools";
25
26 # https://github.com/OpenNMT/CTranslate2/tree/master/python
27 sourceRoot = "${src.name}/python";
28
29 nativeBuildInputs = [
30 pybind11
31 setuptools
32 ];
33
34 buildInputs = [ ctranslate2-cpp ];
35
36 propagatedBuildInputs = [
37 numpy
38 pyyaml
39 ];
40
41 pythonImportsCheck = [
42 # https://opennmt.net/CTranslate2/python/overview.html
43 "ctranslate2"
44 "ctranslate2.converters"
45 "ctranslate2.models"
46 "ctranslate2.specs"
47 ];
48
49 nativeCheckInputs = [
50 pytestCheckHook
51 tensorflow-bin
52 torch
53 transformers
54 wurlitzer
55 ];
56
57 preCheck = ''
58 # run tests against build result, not sources
59 rm -rf ctranslate2
60
61 export HOME=$TMPDIR
62 '';
63
64 disabledTests = [
65 # AssertionError: assert 'int8' in {'float32'}
66 "test_get_supported_compute_types"
67 ];
68
69 disabledTestPaths = [
70 # TODO: ModuleNotFoundError: No module named 'opennmt'
71 "tests/test_opennmt_tf.py"
72 # OSError: We couldn't connect to 'https://huggingface.co' to load this file
73 "tests/test_transformers.py"
74 ];
75
76 meta = with lib; {
77 description = "Fast inference engine for Transformer models";
78 homepage = "https://github.com/OpenNMT/CTranslate2";
79 changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md";
80 license = licenses.mit;
81 maintainers = with maintainers; [ hexa ];
82 };
83}