hysts HF staff commited on
Commit
4049f95
1 Parent(s): 26286d1
Files changed (3) hide show
  1. .pre-commit-config.yaml +1 -1
  2. dualstylegan.py +4 -3
  3. patch +38 -0
.pre-commit-config.yaml CHANGED
@@ -1,4 +1,4 @@
1
- exclude: ^DualStyleGAN
2
  repos:
3
  - repo: https://github.com/pre-commit/pre-commit-hooks
4
  rev: v4.2.0
 
1
+ exclude: ^(DualStyleGAN|patch)
2
  repos:
3
  - repo: https://github.com/pre-commit/pre-commit-hooks
4
  rev: v4.2.0
dualstylegan.py CHANGED
@@ -3,6 +3,7 @@ from __future__ import annotations
3
  import argparse
4
  import os
5
  import pathlib
 
6
  import sys
7
  from typing import Callable, Union
8
 
@@ -14,9 +15,9 @@ import torch
14
  import torch.nn as nn
15
  import torchvision.transforms as T
16
 
17
- if os.environ.get('SYSTEM') == 'spaces':
18
- os.system("sed -i '10,17d' DualStyleGAN/model/stylegan/op/fused_act.py")
19
- os.system("sed -i '10,17d' DualStyleGAN/model/stylegan/op/upfirdn2d.py")
20
 
21
  app_dir = pathlib.Path(__file__).parent
22
  submodule_dir = app_dir / 'DualStyleGAN'
 
3
  import argparse
4
  import os
5
  import pathlib
6
+ import subprocess
7
  import sys
8
  from typing import Callable, Union
9
 
 
15
  import torch.nn as nn
16
  import torchvision.transforms as T
17
 
18
+ if os.getenv('SYSTEM') == 'spaces':
19
+ with open('patch') as f:
20
+ subprocess.run('patch -p1'.split(), cwd='DualStyleGAN', stdin=f)
21
 
22
  app_dir = pathlib.Path(__file__).parent
23
  submodule_dir = app_dir / 'DualStyleGAN'
patch ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ diff --git a/model/stylegan/op/fused_act.py b/model/stylegan/op/fused_act.py
2
+ index c3b735c..67e7972 100644
3
+ --- a/model/stylegan/op/fused_act.py
4
+ +++ b/model/stylegan/op/fused_act.py
5
+ @@ -7,14 +7,6 @@ from torch.autograd import Function
6
+ from torch.utils.cpp_extension import load
7
+
8
+
9
+ -module_path = os.path.dirname(__file__)
10
+ -fused = load(
11
+ - "fused",
12
+ - sources=[
13
+ - os.path.join(module_path, "fused_bias_act.cpp"),
14
+ - os.path.join(module_path, "fused_bias_act_kernel.cu"),
15
+ - ],
16
+ -)
17
+
18
+
19
+ class FusedLeakyReLUFunctionBackward(Function):
20
+ diff --git a/model/stylegan/op/upfirdn2d.py b/model/stylegan/op/upfirdn2d.py
21
+ index 67e0375..97565d7 100644
22
+ --- a/model/stylegan/op/upfirdn2d.py
23
+ +++ b/model/stylegan/op/upfirdn2d.py
24
+ @@ -7,14 +7,6 @@ from torch.autograd import Function
25
+ from torch.utils.cpp_extension import load
26
+
27
+
28
+ -module_path = os.path.dirname(__file__)
29
+ -upfirdn2d_op = load(
30
+ - "upfirdn2d",
31
+ - sources=[
32
+ - os.path.join(module_path, "upfirdn2d.cpp"),
33
+ - os.path.join(module_path, "upfirdn2d_kernel.cu"),
34
+ - ],
35
+ -)
36
+
37
+
38
+ class UpFirDn2dBackward(Function):