about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/text/gpt2tc
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/text/gpt2tc')
-rw-r--r--nixpkgs/pkgs/tools/text/gpt2tc/0001-add-python-shebang.patch10
-rw-r--r--nixpkgs/pkgs/tools/text/gpt2tc/default.nix45
2 files changed, 55 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/tools/text/gpt2tc/0001-add-python-shebang.patch b/nixpkgs/pkgs/tools/text/gpt2tc/0001-add-python-shebang.patch
new file mode 100644
index 000000000000..b47b444009ac
--- /dev/null
+++ b/nixpkgs/pkgs/tools/text/gpt2tc/0001-add-python-shebang.patch
@@ -0,0 +1,10 @@
+diff --git a/gpt2convert.py b/gpt2convert.py
+index 34ca909..6e6cac5 100644
+--- a/gpt2convert.py
++++ b/gpt2convert.py
+@@ -1,3 +1,5 @@
++#!/usr/bin/env python3
++
+ import sys
+ import tensorflow as tf
+ import numpy as np
diff --git a/nixpkgs/pkgs/tools/text/gpt2tc/default.nix b/nixpkgs/pkgs/tools/text/gpt2tc/default.nix
new file mode 100644
index 000000000000..ee78451aae8d
--- /dev/null
+++ b/nixpkgs/pkgs/tools/text/gpt2tc/default.nix
@@ -0,0 +1,45 @@
+{ lib, stdenv, fetchurl, autoPatchelfHook, python3 }:
+
+stdenv.mkDerivation rec {
+  pname = "gpt2tc";
+  version = "2021-04-24";
+
+  src = fetchurl {
+    url = "https://web.archive.org/web/20220603034455/https://bellard.org/libnc/gpt2tc-2021-04-24.tar.gz";
+    hash = "sha256-6oTxnbBwjHAXVrWMjOQVwdODbqLRoinx00pi29ff5w0=";
+  };
+
+  patches = [
+    # Add a shebang to the python script so that nix detects it as such and
+    # wraps it properly. Otherwise, it runs in shell and freezes the system.
+    ./0001-add-python-shebang.patch
+  ];
+
+  nativeBuildInputs = [ autoPatchelfHook ];
+
+  buildInputs = [
+    (python3.withPackages (p: with p; [ numpy tensorflow ]))
+  ];
+
+  installPhase = ''
+    runHook preInstall
+
+    install -D -m755 -t $out/lib libnc${stdenv.hostPlatform.extensions.sharedLibrary}
+    addAutoPatchelfSearchPath $out/lib
+    install -D -m755 -t $out/bin gpt2tc
+    install -T -m755 download_model.sh $out/bin/gpt2-download-model
+    install -T -m755 gpt2convert.py $out/bin/gpt2-convert
+    install -D -m644 -t $out/share/gpt2tc readme.txt gpt2vocab.txt Changelog
+
+    runHook postInstall
+  '';
+
+  meta = with lib; {
+    description = "Text completion and compression using GPT-2";
+    homepage = "https://bellard.org/libnc/gpt2tc.html";
+    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
+    license = licenses.unfree;
+    platforms = [ "x86_64-linux" ];
+    maintainers = with maintainers; [ anna328p ];
+  };
+}