Ver código fonte

package/python-ml-dtypes: new package

ml_dtypes is a stand-alone implementation of several NumPy
dtype extensions used in machine learning libraries.

https://github.com/jax-ml/ml_dtypes

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Julien Olivain 1 ano atrás
pai
commit
ebe47e7605

+ 3 - 0
DEVELOPERS

@@ -1745,6 +1745,7 @@ F:	package/python-magic-wormhole/
 F:	package/python-magic-wormhole-mailbox-server/
 F:	package/python-magic-wormhole-transit-relay/
 F:	package/python-midiutil/
+F:	package/python-ml-dtypes/
 F:	package/python-pyalsa/
 F:	package/python-spake2/
 F:	package/rdma-core/
@@ -1756,6 +1757,7 @@ F:	support/testing/tests/package/sample_python_distro.py
 F:	support/testing/tests/package/sample_python_gnupg.py
 F:	support/testing/tests/package/sample_python_hwdata.py
 F:	support/testing/tests/package/sample_python_midiutil.py
+F:	support/testing/tests/package/sample_python_ml_dtypes.py
 F:	support/testing/tests/package/sample_python_pyalsa.py
 F:	support/testing/tests/package/sample_python_spake2.py
 F:	support/testing/tests/package/test_acpica.py
@@ -1806,6 +1808,7 @@ F:	support/testing/tests/package/test_python_hkdf.py
 F:	support/testing/tests/package/test_python_hwdata.py
 F:	support/testing/tests/package/test_python_magic_wormhole.py
 F:	support/testing/tests/package/test_python_midiutil.py
+F:	support/testing/tests/package/test_python_ml_dtypes.py
 F:	support/testing/tests/package/test_python_pyalsa.py
 F:	support/testing/tests/package/test_python_spake2.py
 F:	support/testing/tests/package/test_rdma_core.py

+ 1 - 0
package/Config.in

@@ -1173,6 +1173,7 @@ menu "External python modules"
 	source "package/python-mimeparse/Config.in"
 	source "package/python-minimalmodbus/Config.in"
 	source "package/python-mistune/Config.in"
+	source "package/python-ml-dtypes/Config.in"
 	source "package/python-modbus-tk/Config.in"
 	source "package/python-more-itertools/Config.in"
 	source "package/python-mpd2/Config.in"

+ 13 - 0
package/python-ml-dtypes/Config.in

@@ -0,0 +1,13 @@
+config BR2_PACKAGE_PYTHON_ML_DTYPES
+	bool "python-ml-dtypes"
+	depends on BR2_PACKAGE_PYTHON_NUMPY_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_MUSL # python-numpy
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_9 # python-numpy
+	depends on BR2_HOST_GCC_AT_LEAST_9 # host-python-numpy
+	select BR2_PACKAGE_PYTHON_NUMPY
+	select BR2_PACKAGE_PYTHON_PYBIND
+	help
+	  ml_dtypes is a stand-alone implementation of several NumPy
+	  dtype extensions used in machine learning libraries.
+
+	  https://github.com/jax-ml/ml_dtypes

+ 5 - 0
package/python-ml-dtypes/python-ml-dtypes.hash

@@ -0,0 +1,5 @@
+# md5, sha256 from https://pypi.org/pypi/ml_dtypes/json
+md5  6adbb05530819bdb4a78d2372d187fe2  ml_dtypes-0.3.1.tar.gz
+sha256  60778f99194b4c4f36ba42da200b35ef851ce4d4af698aaf70f5b91fe70fc611  ml_dtypes-0.3.1.tar.gz
+# Locally computed sha256 checksums
+sha256  cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30  LICENSE

+ 19 - 0
package/python-ml-dtypes/python-ml-dtypes.mk

@@ -0,0 +1,19 @@
+################################################################################
+#
+# python-ml-dtypes
+#
+################################################################################
+
+PYTHON_ML_DTYPES_VERSION = 0.3.1
+PYTHON_ML_DTYPES_SOURCE = ml_dtypes-$(PYTHON_ML_DTYPES_VERSION).tar.gz
+PYTHON_ML_DTYPES_SITE = https://files.pythonhosted.org/packages/16/6e/9a7a51ee1ca24b8e92109128260c5aec8340c8fe5572e9ceecddae559abe
+PYTHON_ML_DTYPES_LICENSE = Apache-2.0
+PYTHON_ML_DTYPES_LICENSE_FILES = LICENSE
+PYTHON_ML_DTYPES_SETUP_TYPE = distutils
+
+PYTHON_ML_DTYPES_DEPENDENCIES = \
+	host-python-numpy \
+	python-numpy \
+	python-pybind
+
+$(eval $(python-package))

+ 39 - 0
support/testing/tests/package/sample_python_ml_dtypes.py

@@ -0,0 +1,39 @@
+#! /usr/bin/env python3
+
+# Tests inspired from commands published on project page:
+# https://pypi.org/project/ml-dtypes/
+
+from ml_dtypes import bfloat16
+
+import numpy as np
+
+a = np.zeros(4, dtype=bfloat16)
+assert a.dtype.name == 'bfloat16'
+assert a[0] == 0.0
+
+types = [
+    'bfloat16',
+    'float8_e4m3b11fnuz',
+    'float8_e4m3fn',
+    'float8_e4m3fnuz',
+    'float8_e5m2',
+    'int4',
+    'uint4'
+]
+for t in types:
+    dtype = np.dtype(t)
+    assert dtype.name == t
+
+rng = np.random.default_rng(seed=0)
+vals = rng.uniform(size=10000).astype(bfloat16)
+sum_vals = vals.sum()
+assert sum_vals == 256
+
+b = bfloat16(256) + bfloat16(1)
+assert b == 256
+
+c = np.nextafter(bfloat16(256), bfloat16(np.inf))
+assert c == 258
+
+d = vals.sum(dtype='float32').astype(bfloat16)
+assert d > 4500 and d < 5500

+ 20 - 0
support/testing/tests/package/test_python_ml_dtypes.py

@@ -0,0 +1,20 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3MlDtypes(TestPythonPackageBase):
+    __test__ = True
+
+    # Note: BR2_PACKAGE_PYTHON3_ZLIB=y is needed as a runtime
+    # dependency because the Bootlin toolchain used for this test is
+    # tainted with zlib (and gets detected by python3/numpy).
+    # See commit 8ce33fed "package/gdb: gdbserver does not need zlib".
+    # This config entry can be removed as soon as the toolchain is
+    # updated without zlib in its sysroot.
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON3_ZLIB=y
+        BR2_PACKAGE_PYTHON_ML_DTYPES=y
+        """
+    sample_scripts = ["tests/package/sample_python_ml_dtypes.py"]
+    timeout = 20