From patchwork Wed Mar 20 22:38:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Elsing X-Patchwork-Id: 62093 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 3FD8727BBEB; Wed, 20 Mar 2024 22:41:39 +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 2EB9C27BBE2 for ; Wed, 20 Mar 2024 22:41:38 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rn4c8-00066n-Uy; Wed, 20 Mar 2024 18:40:52 -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 1rn4br-000605-F2 for guix-patches@gnu.org; Wed, 20 Mar 2024 18:40:36 -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 1rn4br-0007e4-4N for guix-patches@gnu.org; Wed, 20 Mar 2024 18:40:35 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rn4cU-0006FS-LS for guix-patches@gnu.org; Wed, 20 Mar 2024 18:41:14 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#69591] [PATCH v3 25/32] gnu: Add qnnpack-pytorch. Resent-From: David Elsing Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 20 Mar 2024 22:41: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.171097445823782 (code B ref 69591); Wed, 20 Mar 2024 22:41:14 +0000 Received: (at 69591) by debbugs.gnu.org; 20 Mar 2024 22:40:58 +0000 Received: from localhost ([127.0.0.1]:36840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rn4cD-0006BP-Nx for submit@debbugs.gnu.org; Wed, 20 Mar 2024 18:40:58 -0400 Received: from mout02.posteo.de ([185.67.36.66]:42103) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rn4bR-00064a-Qa for 69591@debbugs.gnu.org; Wed, 20 Mar 2024 18:40:12 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 99FCF240101 for <69591@debbugs.gnu.org>; Wed, 20 Mar 2024 23:39:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1710974364; bh=dWr8XBVvFnqerSAo8OpUP0rE1yqt/L8xDG6HXuH53zk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=q3U8RjLYa3K60BaTqFpuh7r9xNDy9MKWNFxBdlguhITRGXokm1RycASYRu1KmS3H3 cLZKGPxQjg1h0sf8q4GZZHnqdNhlk2AaHonnKAM66SlYm8u24BiXYT0CvInsu3dx8g LsgMYH8dr7AFfZYnsGlU+2GR3m15lTG3SN/6P8+mkNj59qt2vZ6WczMUa/ANszQYQm L7xDR32kSrBHBQHR+9eVoQ9rQZ0fPWY4HR8CdTgs3fkT1BLnK1J6HPsGs5+XRf+9aK mj7uxyRFh9N6BXxvLHi4KaxSbAXPj+eM/kkBepMn7Cq4oQfZTECIC4lyP/Y7H0whgK XkDfDQnPux66A== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4V0Nn82Bxvz6twQ; Wed, 20 Mar 2024 23:39:24 +0100 (CET) From: David Elsing Date: Wed, 20 Mar 2024 22:38:50 +0000 Message-ID: <20240320223906.13214-25-david.elsing@posteo.net> In-Reply-To: <20240320223737.12883-1-david.elsing@posteo.net> References: <20240320223737.12883-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 6c5b723559..c4785ac2f1 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -4313,6 +4313,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