From patchwork Tue Mar 12 22:51:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Elsing X-Patchwork-Id: 61740 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 C365A27BBE9; Tue, 12 Mar 2024 22:55:35 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED 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 AD72227BBE2 for ; Tue, 12 Mar 2024 22:55:33 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkB11-00012p-LU; Tue, 12 Mar 2024 18:54:35 -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 1rkB07-0000C5-Vt for guix-patches@gnu.org; Tue, 12 Mar 2024 18:53:42 -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 1rkB07-0000Mg-Nt for guix-patches@gnu.org; Tue, 12 Mar 2024 18:53:39 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rkB0g-0001oo-DY for guix-patches@gnu.org; Tue, 12 Mar 2024 18:54:14 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#69591] [PATCH v2 25/31] gnu: Add qnnpack-pytorch. Resent-From: David Elsing Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 12 Mar 2024 22:54:14 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69591 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69591@debbugs.gnu.org Cc: David Elsing Received: via spool by 69591-submit@debbugs.gnu.org id=B69591.17102840266747 (code B ref 69591); Tue, 12 Mar 2024 22:54:14 +0000 Received: (at 69591) by debbugs.gnu.org; 12 Mar 2024 22:53:46 +0000 Received: from localhost ([127.0.0.1]:44112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkB0E-0001ke-07 for submit@debbugs.gnu.org; Tue, 12 Mar 2024 18:53:46 -0400 Received: from mout01.posteo.de ([185.67.36.65]:59085) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkAzm-0001ff-Q5 for 69591@debbugs.gnu.org; Tue, 12 Mar 2024 18:53:22 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 741F0240027 for <69591@debbugs.gnu.org>; Tue, 12 Mar 2024 23:52:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1710283958; bh=12BjuyeCmJcEwwgXqUjYDs71wxVTawonTm/p4uzNZf0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=HufO7j7hu7e67GbdXuV01QJGNEVARNIy95QZ6NxQgJ9AZlzKOY5RjXVo0bwQof2CM zmEImHnrflpDB+BOFB2NtZNWOgcXcPJ9SzbcziyVzBa5z8gAbfwDJcgOF+e1MWVuXD MZ5aOg7WN6BqwKgPQP15DD6MFzynTjq3lgM8QmdQFKJY3AoZCmVztAmLLT1SlVDllu 7rYaSQQntAXGFMBxbaA81s3zInBRIn9zhmyhSRNe6E49+N4C3cyOQcf4eyYhD2ofuN 3rDEJ7JLY3fpZG+o7nsNwA/1QbgUEdzOnbGej9mWX25soMA9/tLnuwwRNtwrjr0gA4 d3Hvl/DlIfLWw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TvTS60dBCz6txW; Tue, 12 Mar 2024 23:52:38 +0100 (CET) From: David Elsing Date: Tue, 12 Mar 2024 22:51:53 +0000 Message-ID: <20240312225211.16427-25-david.elsing@posteo.net> In-Reply-To: <20240312224712.15578-1-david.elsing@posteo.net> References: <20240312224712.15578-1-david.elsing@posteo.net> MIME-Version: 1.0 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: , 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 This is an internal fork of QNNPACK in the PyTorch source tree. * gnu/packages/machine-learning.scm (%python-pytorch-version): New variable. (%python-pytorch-src): New variable. (qnnpack-pytorch): New variable. --- gnu/packages/machine-learning.scm | 127 ++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index 24422e6965..6b62d7016b 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -4311,6 +4311,133 @@ (define-public ideep-pytorch PyTorch.") (license license:expat))) +(define %python-pytorch-version "2.2.1") + +(define %python-pytorch-src + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/pytorch/pytorch") + (commit (string-append "v" %python-pytorch-version)))) + (file-name (git-file-name "python-pytorch" %python-pytorch-version)) + (sha256 + (base32 + "03mm0pwwb5lxdsmmiw3cch9fijgjw81kmmc4ln9rlyazkm7l1r48")) + (modules '((guix build utils))) + (snippet + '(begin + ;; Bundled or unused code + (for-each + (lambda (dir) + (when (file-exists? dir) + (delete-file-recursively dir))) + '("android" + "aten/src/ATen/native/cuda/cutlass_extensions" + "aten/src/ATen/native/quantized/cpu/qnnpack" + "caffe2/mobile/contrib/libopencl-stub" + "caffe2/mobile/contrib/libvulkan-stub" + "third_party")) + + ;; Autogenerated files + (for-each + delete-file + '("aten/src/ATen/nnapi/nnapi_wrapper.cpp" + "aten/src/ATen/nnapi/nnapi_wrapper.h" + "caffe2/mobile/contrib/ios/mpscnn/mpscnn_kernels.h" + "caffe2/proto/caffe2_legacy_pb2.pyi" + "caffe2/proto/caffe2_pb2.pyi" + "caffe2/proto/hsm_pb2.pyi" + "caffe2/proto/metanet_pb2.pyi" + "caffe2/proto/predictor_consts_pb2.pyi" + "caffe2/proto/prof_dag_pb2.pyi" + "caffe2/proto/torch_pb2.pyi" + ;; These files contain just lists of floating point values and + ;; might be as well hand-written. + ;; "test/cpp/api/init_baseline.h" + ;; "test/cpp/api/optim_baseline.h" + "test/mobile/test_upgrader_bytecode_table_example.cpp" + "torch/csrc/jit/mobile/upgrader_mobile.cpp" + "torch/csrc/jit/runtime/decomposition_registry_util.cpp" + "torch/csrc/jit/runtime/serialized_shape_function_registry.cpp" + "torch/csrc/jit/tensorexpr/external_functions_codegen.cpp" + "torch/csrc/jit/serialization/mobile_bytecode_generated.h")) + (delete-file-recursively ".github") + (for-each + (lambda (dir) + (for-each + delete-file + (find-files dir "\\.cu$"))) + '("aten/src/ATen/native/transformers/cuda/flash_attn/kernels" + "aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels")))))) + +(define-public qnnpack-pytorch + (package + (inherit qnnpack) + (name "qnnpack-pytorch") + (version (string-append "pytorch-" %python-pytorch-version)) + (source + (origin + (inherit %python-pytorch-src) + (patches '()) + (modules '((guix build utils) + (srfi srfi-26) + (ice-9 ftw))) + (snippet + '(begin + (rename-file "aten/src/ATen/native/quantized/cpu/qnnpack" + "../qnnpack") + (let ((outdir (getcwd))) + (chdir "..") + (rename-file outdir "dummy") + (rename-file "qnnpack" outdir) + (chdir outdir) + (delete-file-recursively "deps")))))) + (arguments + (substitute-keyword-arguments (package-arguments qnnpack) + ((#:phases phases #~%standard-phases) + #~(modify-phases %standard-phases + (add-after 'unpack 'patch-cmake + (lambda _ + (substitute* "CMakeLists.txt" + (("project\\(.*" orig) + (apply + string-append + orig "\n" + (map (lambda (name) + (string-append + "option(" name " \"\" ON)\n")) + '("USE_SYSTEM_CPUINFO" "USE_SYSTEM_FP16" "USE_SYSTEM_FXDIV" + "USE_SYSTEM_PSIMD" "USE_SYSTEM_PTHREADPOOL")))) + (("if.*SOURCE_DIR.*") + "if(FALSE)\n") + (("if\\(NOT TARGET (clog|gtest|benchmark).*") + "if(FALSE)\n") + (("target_link_libraries.*(fxdiv|psimd|fp16)\\).*") + "") + (("(target_link_libraries.*) fp16 (.*)" _ before after) + (string-append before " " after))))) + (add-after 'unpack 'fix-cstring-include + (lambda _ + (substitute* "include/pack_block_sparse.h" + (("#include.*.*" orig) + (string-append orig "\n#include \n"))))) + (add-after 'install 'install-missing-headers + (lambda _ + (for-each + (lambda (name) + (install-file (string-append "../source/include/" name) + (string-append #$output "/include"))) + '("pack_block_sparse.h" + "pytorch_qnnpack.h" + "qnnpack_func.h")) + (copy-recursively + "../source/src/qnnpack" + (string-append #$output "/include/qnnpack")))))) + ;; Some tests occasionally fail on i686 due to floating point rounding. + ((#:tests? _ #t) + (not (string-prefix? "i686" (or (%current-target-system) + (%current-system))))))))) + ;; Please also update python-torchvision when updating this package. (define-public python-pytorch (package