jennyxue commited on
Commit
05c8659
·
verified ·
1 Parent(s): 06744e3

fp16 build of DeepFilterNet3

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ fp16/df_dec.engine filter=lfs diff=lfs merge=lfs -text
37
+ fp16/enc.engine filter=lfs diff=lfs merge=lfs -text
38
+ fp16/erb_dec.engine filter=lfs diff=lfs merge=lfs -text
fp16/df_dec.engine ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae36125e774888610b08bf6e4fce1e9a3478a1fd927033108147fa900dbbae08
3
+ size 52106244
fp16/enc.engine ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:85732e2dbcdaf06b799ffacbca0f93729418a44c39828ae7880602aa1fbb5584
3
+ size 50583908
fp16/erb_dec.engine ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d32a83bb3c6d87cfe50ebddb43b0b441315cb404c72282ee8086d56e05b3d427
3
+ size 52348612
fp16/trt_runner.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """A minimal TensorRT engine runner: numpy in, numpy out (tensorrt-cu12 10.x and polygraphy; no torch).
2
+
3
+ from trt_runner import Engine
4
+ e = Engine("model.engine")
5
+ out = e({"input": x}) # dict of output name -> numpy array
6
+ """
7
+ from __future__ import annotations
8
+
9
+ from pathlib import Path
10
+
11
+ import numpy as np
12
+
13
+
14
+ def lean_dlls():
15
+ """Version-compatible engines are built against and run on TensorRT's lean runtime (pip tensorrt-lean-cu12):
16
+ put its DLL folder on the search path (Windows)."""
17
+ import importlib.util
18
+ import os
19
+ spec = importlib.util.find_spec("tensorrt_lean_libs")
20
+ if spec and spec.submodule_search_locations:
21
+ d = list(spec.submodule_search_locations)[0]
22
+ os.environ["PATH"] = d + os.pathsep + os.environ.get("PATH", "")
23
+ if hasattr(os, "add_dll_directory"):
24
+ os.add_dll_directory(d)
25
+
26
+
27
+ class Engine:
28
+ def __init__(self, path):
29
+ lean_dlls()
30
+ import tensorrt as trt
31
+ from polygraphy.backend.trt import TrtRunner
32
+ self.trt = trt
33
+ logger = trt.Logger(trt.Logger.WARNING)
34
+ runtime = trt.Runtime(logger)
35
+ runtime.engine_host_code_allowed = True # version-compatible engines carry their own lean runtime
36
+ engine = runtime.deserialize_cuda_engine(Path(path).read_bytes())
37
+ if engine is None:
38
+ raise RuntimeError(f"could not load {path} (TensorRT {trt.__version__}; the engine needs TensorRT 10.x "
39
+ "and an RTX 30-series or newer GPU)")
40
+ self.engine = engine
41
+ self.runner = TrtRunner(engine)
42
+ self.runner.activate()
43
+ self.inputs = [engine.get_tensor_name(i) for i in range(engine.num_io_tensors)
44
+ if engine.get_tensor_mode(engine.get_tensor_name(i)) == trt.TensorIOMode.INPUT]
45
+
46
+ def __call__(self, feed: dict) -> dict:
47
+ feed = {k: np.ascontiguousarray(v) for k, v in feed.items() if k in self.inputs}
48
+ out = self.runner.infer(feed, check_inputs=True)
49
+ return {k: np.array(v) for k, v in out.items()}
50
+
51
+ def close(self):
52
+ self.runner.deactivate()
53
+
54
+ def __del__(self):
55
+ try:
56
+ self.close()
57
+ except Exception:
58
+ pass