From patchwork Sun Sep 8 14:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 67765 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1FCE927BBEA; Sun, 8 Sep 2024 15:41:31 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 84DC327BBE2 for ; Sun, 8 Sep 2024 15:41:30 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snJ68-0001c5-36; Sun, 08 Sep 2024 10:41:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1snJ66-0001b0-Fk for guix-patches@gnu.org; Sun, 08 Sep 2024 10:41:02 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1snJ66-00006f-6C for guix-patches@gnu.org; Sun, 08 Sep 2024 10:41:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=sleye7OjtxtFNLDuzVJoHOkp4CXf4lFYvZR13+UshUM=; b=lZcEOA0woZq8tN3jvB60fV0OWZCMGeCTam202VWRms32e8NwaZhvCeOYws/91vDifFRNwoUJlFO1gz+cASBLDANNNO8rh3rKmmr7MM9r3DvJKuKFu9+jPFwEeRmUblsErnLD1DnE5xhbN13T3O7ksYZM1cahNl0cU8d3b3/a0k1jeusaYH6J4hA/MBJRNE0Haee1UHeSw8THvEjcRRBVSe3Gc8L692APh8lE/qDfknqyI8YmEC6nRcydII5FOugdaNyhCmpOSpWkf4cvzVU0IkwfHT3rj58kEMDPtby8ZDJHo0GXRp+TdzH0TBnkOaUCuTObKOvHzc/ps9P19eW7kg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1snJ68-0000Sa-DL for guix-patches@gnu.org; Sun, 08 Sep 2024 10:41:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73094] [PATCH v2 10/10] gnu: Add python-safetensors. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 08 Sep 2024 14:41:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73094 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73094@debbugs.gnu.org Cc: herman@rimm.ee, ngraves@ngraves.fr Received: via spool by 73094-submit@debbugs.gnu.org id=B73094.17258064161658 (code B ref 73094); Sun, 08 Sep 2024 14:41:04 +0000 Received: (at 73094) by debbugs.gnu.org; 8 Sep 2024 14:40:16 +0000 Received: from localhost ([127.0.0.1]:59856 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snJ5L-0000Qa-FW for submit@debbugs.gnu.org; Sun, 08 Sep 2024 10:40:16 -0400 Received: from 3.mo560.mail-out.ovh.net ([46.105.58.226]:44065) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snJ5G-0000MF-IF for 73094@debbugs.gnu.org; Sun, 08 Sep 2024 10:40:11 -0400 Received: from director10.ghost.mail-out.ovh.net (unknown [10.109.139.172]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id 4X1t0l1Hw6z1YnL for <73094@debbugs.gnu.org>; Sun, 8 Sep 2024 14:40:07 +0000 (UTC) Received: from ghost-submission-55b549bf7b-rbfzq (unknown [10.108.54.173]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 9731B1FDDC; Sun, 8 Sep 2024 14:40:06 +0000 (UTC) Received: from ngraves.fr ([37.59.142.102]) by ghost-submission-55b549bf7b-rbfzq with ESMTPSA id LdvRD0a33WZRRwAAT9tbQA (envelope-from ); Sun, 08 Sep 2024 14:40:06 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-102R0044f0f7804-6e6b-4bd5-8b2c-bfd5900ff0cc, 1B24502937BE6AAC558E984F82BC0F282F1693D3) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 81.67.146.208 Date: Sun, 8 Sep 2024 16:39:26 +0200 Message-ID: <20240908143935.22543-10-ngraves@ngraves.fr> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240908143935.22543-1-ngraves@ngraves.fr> References: <20240908143935.22543-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13206524434405712517 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeeftddrudeihedgkedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepkeegjedtieegieetkeejueejgedtkeekvdegheevfeeivdeiuedvhfdvuddtgfetnecuffhomhgrihhnpehhuhhgghhinhhgfhgrtggvrdgtohenucfkphepuddvjedrtddrtddruddpkedurdeijedrudegiedrvddtkedpfeejrdehledrudegvddruddtvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeeftdelgeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheeitddpmhhouggvpehsmhhtphhouhht DKIM-Signature: a=rsa-sha256; bh=sleye7OjtxtFNLDuzVJoHOkp4CXf4lFYvZR13+UshUM=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1725806407; v=1; b=TcZ8cLMAr3gYVZJqu9Wk2J1fyf+FVdXDyXlHUlF1i4vsuyLSmzWxjhCy86VmhsaJBiZlNI2f G9G8inNc8MitNb+vRVPIEmy/bKvM25A0uQg8dVCAZHaQDR+FjEoZIDKme5TFAZYEE8ArWL1ovVR frKdjN9MZJBLlfOSYvw44XYFKIJpUir0vswBt8sVRuG7z1DzwzEPdrD0xvFrJL4yafzhjDcalSo 5WJwNOknb453Xr3ltQ/bsrOzrVxLc6eFCc8FM55o3AriOsJzDFdNV9WR7acxQNcdp2EJrr7zsjm cAxolms+ooxVRSqiYvae65YY9g8scILjxGIeRCE4nV2sw== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/packages/machine-learning.scm (python-safetensors): New variable. Change-Id: I90a1684d06756ce87ca0862d745a75be5919f0b2 --- gnu/packages/machine-learning.scm | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index a4aeb97be7..5006ba7ca0 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -1120,6 +1120,102 @@ (define-public rust-safetensors @code{PyTorch} counterparts.") (license license:asl2.0))) +(define-public python-safetensors + (package + (name "python-safetensors") + (version "0.4.3") + (source + (origin + (method url-fetch) + (uri (pypi-uri "safetensors" version)) + (sha256 + (base32 "1hhiwy67jarm70l0k26fs1cjhzkgzrh79q14bklj2yp0qi8gr19g")) + (modules '((guix build utils) + (ice-9 ftw))) + (snippet + #~(begin ;; Only keeping bindings. + (for-each (lambda (file) + (unless (member file '("." ".." "bindings" "PKG-INFO")) + (delete-file-recursively file))) + (scandir ".")) + (for-each (lambda (file) + (unless (member file '("." "..")) + (rename-file (string-append "bindings/python/" file) file))) + (scandir "bindings/python")))))) + (build-system cargo-build-system) + (arguments + (list + #:modules '((guix build cargo-build-system) + (guix build utils) + (ice-9 regex) + (ice-9 textual-ports)) + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack-rust-crates 'inject-safetensors + (lambda _ + (substitute* "Cargo.toml" + (("\\[dependencies\\]") + (format #f "[dependencies]~%safetensors = ~s" + #$(package-version rust-safetensors)))) + (call-with-input-file "Cargo.toml" + (lambda (port) + (let* ((content (get-string-all port)) + (top-match (string-match + "\\[dependencies.safetensors" content))) + (call-with-output-file "Cargo.toml" + (lambda (out) + (format out "~a" (match:prefix top-match))))))))) + (add-before 'check 'install-rust-library + (lambda _ + (copy-file "target/release/libsafetensors_rust.so" + "py_src/safetensors/_safetensors_rust.so"))) + (replace 'check + (lambda _ + (invoke "python3" + "-c" (format #f + "import sys; sys.path.append(\"~a/py_src\")" + (getcwd)) + "-m" "pytest" + "-n" "auto" + "--dist=loadfile" + "-s" "-v" "./tests/" + ;; Missing jax dependency + "--ignore=./tests/test_flax_comparison.py"))) + (add-after 'install 'install-python + (lambda _ + (let* ((pversion #$(version-major+minor (package-version python))) + (lib (string-append #$output "/lib/python" pversion + "/site-packages/")) + (info (string-append lib "safetensors-" + #$(package-version this-package) + ".dist-info"))) + (mkdir-p info) + (copy-file "PKG-INFO" (string-append info "/METADATA")) + (copy-recursively + "py_src/safetensors" + (string-append lib "safetensors")))))) + #:cargo-inputs + `(("rust-pyo3" ,rust-pyo3-0.21) + ("rust-memmap2" ,rust-memmap2-0.9) + ("rust-safetensors" ,rust-safetensors) + ("rust-serde-json" ,rust-serde-json-1)))) + (inputs + (list rust-safetensors)) + (native-inputs + (list python-h5py + python-minimal + python-numpy + python-pytest + python-pytest-xdist + python-pytorch + tensorflow)) + (home-page "https://huggingface.co/docs/safetensors") + (synopsis "Simple and safe way to store and distribute tensors") + (description "This package provides a fast (zero-copy) and safe +(dedicated) format for storing tensors safely. This package builds upon +@code{rust-safetensors} and provides Python bindings.") + (license license:asl2.0))) + (define-public python-sentencepiece (package (name "python-sentencepiece")