Skip to content

Commit 0fd4e6c

Browse files
authored
Lint unused import (comfyanonymous#5973)
* Lint unused import * nit * Remove unused imports * revert fix_torch import * nit
1 parent e2fafe0 commit 0fd4e6c

40 files changed

+39
-75
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[MESSAGES CONTROL]
22
disable=all
3-
enable=eval-used
3+
enable=eval-used, unused-import

comfy/cldm/cldm.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
#and modified
33

44
import torch
5-
import torch as th
65
import torch.nn as nn
76

87
from ..ldm.modules.diffusionmodules.util import (
9-
zero_module,
108
timestep_embedding,
119
)
1210

comfy/cldm/dit_embedder.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import math
22
from typing import List, Optional, Tuple
33

4-
import numpy as np
54
import torch
65
import torch.nn as nn
7-
from einops import rearrange
86
from torch import Tensor
97

108
from comfy.ldm.modules.diffusionmodules.mmdit import DismantledBlock, PatchEmbed, VectorEmbedder, TimestepEmbedder, get_2d_sincos_pos_embed_torch

comfy/cldm/mmdit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import torch
2-
from typing import Dict, Optional
2+
from typing import Optional
33
import comfy.ldm.modules.diffusionmodules.mmdit
44

55
class ControlNet(comfy.ldm.modules.diffusionmodules.mmdit.MMDiT):

comfy/extra_samplers/uni_pc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#code taken from: https://github.com/wl-zhao/UniPC and modified
22

33
import torch
4-
import torch.nn.functional as F
54
import math
65

7-
from tqdm.auto import trange, tqdm
6+
from tqdm.auto import trange
87

98

109
class NoiseScheduleVP:

comfy/ldm/audio/autoencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import torch
44
from torch import nn
5-
from typing import Literal, Dict, Any
5+
from typing import Literal
66
import math
77
import comfy.ops
88
ops = comfy.ops.disable_weight_init

comfy/ldm/audio/embedders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import torch
44
import torch.nn as nn
5-
from torch import Tensor, einsum
6-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union
5+
from torch import Tensor
6+
from typing import List, Union
77
from einops import rearrange
88
import math
99
import comfy.ops

comfy/ldm/cascade/controlnet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
"""
1818

19-
import torch
2019
import torchvision
2120
from torch import nn
2221
from .common import LayerNorm2d_op

comfy/ldm/flux/controlnet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
from torch import Tensor, nn
77
from einops import rearrange, repeat
88

9-
from .layers import (DoubleStreamBlock, EmbedND, LastLayer,
10-
MLPEmbedder, SingleStreamBlock,
11-
timestep_embedding)
9+
from .layers import (timestep_embedding)
1210

1311
from .model import Flux
1412
import comfy.ldm.common_dit

comfy/ldm/genmo/joint_model/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#original code from https://github.com/genmoai/models under apache 2.0 license
22
#adapted to ComfyUI
33

4-
from typing import Optional, Tuple
4+
from typing import Optional
55

66
import torch
77
import torch.nn as nn

comfy/ldm/genmo/vae/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#original code from https://github.com/genmoai/models under apache 2.0 license
22
#adapted to ComfyUI
33

4-
from typing import Callable, List, Optional, Tuple, Union
4+
from typing import List, Optional, Tuple, Union
55
from functools import partial
66
import math
77

comfy/ldm/hydit/controlnet.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
from typing import Any, Optional
21

32
import torch
43
import torch.nn as nn
5-
import torch.nn.functional as F
64

7-
from torch.utils import checkpoint
85

96
from comfy.ldm.modules.diffusionmodules.mmdit import (
10-
Mlp,
117
TimestepEmbedder,
128
PatchEmbed,
13-
RMSNorm,
149
)
15-
from comfy.ldm.modules.diffusionmodules.util import timestep_embedding
1610
from .poolers import AttentionPool
1711

1812
import comfy.latent_formats
1913
from .models import HunYuanDiTBlock, calc_rope
2014

21-
from .posemb_layers import get_2d_rotary_pos_embed, get_fill_resize_and_crop
2215

2316

2417
class HunYuanControlNet(nn.Module):

comfy/ldm/hydit/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
from typing import Any
21

32
import torch
43
import torch.nn as nn
5-
import torch.nn.functional as F
64

75
import comfy.ops
86
from comfy.ldm.modules.diffusionmodules.mmdit import Mlp, TimestepEmbedder, PatchEmbed, RMSNorm

comfy/ldm/hydit/poolers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import torch
22
import torch.nn as nn
3-
import torch.nn.functional as F
43
from comfy.ldm.modules.attention import optimized_attention
54
import comfy.ops
65

comfy/ldm/lightricks/vae/causal_video_autoencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from functools import partial
44
import math
55
from einops import rearrange
6-
from typing import Any, Mapping, Optional, Tuple, Union, List
6+
from typing import Optional, Tuple, Union
77
from .conv_nd_factory import make_conv_nd, make_linear_nd
88
from .pixel_norm import PixelNorm
99

comfy/ldm/lightricks/vae/conv_nd_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Tuple, Union
22

3-
import torch
43

54
from .dual_conv3d import DualConv3d
65
from .causal_conv3d import CausalConv3d

comfy/ldm/models/autoencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import torch
22
from contextlib import contextmanager
3-
from typing import Any, Dict, List, Optional, Tuple, Union
3+
from typing import Any, Dict, Tuple, Union
44

55
from comfy.ldm.modules.distributions.distributions import DiagonalGaussianDistribution
66

comfy/ldm/modules/diffusionmodules/mmdit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
import math
31
from typing import Dict, Optional, List
42

53
import numpy as np

comfy/ldm/modules/diffusionmodules/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import torch
44
import torch.nn as nn
55
import numpy as np
6-
from typing import Optional, Any
76
import logging
87

98
from comfy import model_management

comfy/ldm/modules/diffusionmodules/openaimodel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from .util import (
1010
checkpoint,
1111
avg_pool_nd,
12-
zero_module,
1312
timestep_embedding,
1413
AlphaBlender,
1514
)

comfy/ldm/modules/diffusionmodules/upscaling.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from functools import partial
55

66
from .util import extract_into_tensor, make_beta_schedule
7-
from comfy.ldm.util import default
87

98

109
class AbstractLowScaleModel(nn.Module):

comfy/ldm/modules/diffusionmodules/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# thanks!
99

1010

11-
import os
1211
import math
1312
import torch
1413
import torch.nn as nn

comfy/ldm/modules/temporal_ae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import functools
2-
from typing import Callable, Iterable, Union
2+
from typing import Iterable, Union
33

44
import torch
55
from einops import rearrange, repeat

comfy/sampler_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22
import uuid
3-
import torch
43
import comfy.model_management
54
import comfy.conds
65
import comfy.utils

comfy/text_encoders/spiece_tokenizer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import torch
32

43
class SPieceTokenizer:

comfy_extras/nodes_advanced_samplers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import comfy.utils
33
import torch
44
import numpy as np
5-
from tqdm.auto import trange, tqdm
6-
import math
5+
from tqdm.auto import trange
76

87

98
@torch.no_grad()

comfy_extras/nodes_clip_sdxl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import torch
21
from nodes import MAX_RESOLUTION
32

43
class CLIPTextEncodeSDXLRefiner:

comfy_extras/nodes_compositing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import numpy as np
21
import torch
32
import comfy.utils
43
from enum import Enum

comfy_extras/nodes_hooks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections.abc import Iterable
55

66
if TYPE_CHECKING:
7-
from comfy.model_patcher import ModelPatcher
87
from comfy.sd import CLIP
98

109
import comfy.hooks

comfy_extras/nodes_model_advanced.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import folder_paths
21
import comfy.sd
32
import comfy.model_sampling
43
import comfy.latent_formats

comfy_extras/nodes_model_downscale.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import torch
21
import comfy.utils
32

43
class PatchModelAddDownscale:

comfy_extras/nodes_upscale_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import logging
32
from spandrel import ModelLoader, ImageModelDescriptor
43
from comfy import model_management

custom_nodes/websocket_image_save.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from PIL import Image, ImageOps
2-
from io import BytesIO
1+
from PIL import Image
32
import numpy as np
4-
import struct
53
import comfy.utils
64
import time
75

execution.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from comfy_execution.graph_utils import is_link, GraphBuilder
1818
from comfy_execution.caching import HierarchicalCache, LRUCache, CacheKeySetInputSignature, CacheKeySetID
1919
from comfy_execution.validation import validate_node_input
20-
from comfy.cli_args import args
2120

2221
class ExecutionResult(Enum):
2322
SUCCESS = 0

fix_torch.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
import logging
66

77

8-
torch_spec = importlib.util.find_spec("torch")
9-
for folder in torch_spec.submodule_search_locations:
10-
lib_folder = os.path.join(folder, "lib")
11-
test_file = os.path.join(lib_folder, "fbgemm.dll")
12-
dest = os.path.join(lib_folder, "libomp140.x86_64.dll")
13-
if os.path.exists(dest):
14-
break
15-
16-
with open(test_file, 'rb') as f:
17-
contents = f.read()
18-
if b"libomp140.x86_64.dll" not in contents:
8+
def fix_pytorch_libomp():
9+
"""
10+
Fix PyTorch libomp DLL issue on Windows by copying the correct DLL file if needed.
11+
"""
12+
torch_spec = importlib.util.find_spec("torch")
13+
for folder in torch_spec.submodule_search_locations:
14+
lib_folder = os.path.join(folder, "lib")
15+
test_file = os.path.join(lib_folder, "fbgemm.dll")
16+
dest = os.path.join(lib_folder, "libomp140.x86_64.dll")
17+
if os.path.exists(dest):
1918
break
20-
try:
21-
mydll = ctypes.cdll.LoadLibrary(test_file)
22-
except FileNotFoundError as e:
23-
logging.warning("Detected pytorch version with libomp issue, patching.")
24-
shutil.copyfile(os.path.join(lib_folder, "libiomp5md.dll"), dest)
19+
20+
with open(test_file, "rb") as f:
21+
contents = f.read()
22+
if b"libomp140.x86_64.dll" not in contents:
23+
break
24+
try:
25+
mydll = ctypes.cdll.LoadLibrary(test_file)
26+
except FileNotFoundError as e:
27+
logging.warning("Detected pytorch version with libomp issue, patching.")
28+
shutil.copyfile(os.path.join(lib_folder, "libiomp5md.dll"), dest)

folder_paths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55
import mimetypes
66
import logging
7-
from typing import Set, List, Dict, Tuple, Literal
7+
from typing import Literal
88
from collections.abc import Collection
99

1010
supported_pt_extensions: set[str] = {'.ckpt', '.pt', '.bin', '.pth', '.safetensors', '.pkl', '.sft'}
@@ -133,7 +133,7 @@ def get_directory_by_type(type_name: str) -> str | None:
133133
return get_input_directory()
134134
return None
135135

136-
def filter_files_content_types(files: List[str], content_types: Literal["image", "video", "audio"]) -> List[str]:
136+
def filter_files_content_types(files: list[str], content_types: Literal["image", "video", "audio"]) -> list[str]:
137137
"""
138138
Example:
139139
files = os.listdir(folder_paths.get_input_directory())

latent_preview.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import torch
22
from PIL import Image
3-
import struct
4-
import numpy as np
53
from comfy.cli_args import args, LatentPreviewMethod
64
from comfy.taesd.taesd import TAESD
75
import comfy.model_management

main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ def execute_script(script_path):
8787

8888
if args.windows_standalone_build:
8989
try:
90-
import fix_torch
90+
from fix_torch import fix_pytorch_libomp
91+
fix_pytorch_libomp()
9192
except:
9293
pass
9394

script_examples/basic_api_example.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
2-
from urllib import request, parse
3-
import random
2+
from urllib import request
43

54
#This is the ComfyUI api prompt format.
65

tests/inference/test_inference.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from copy import deepcopy
22
from io import BytesIO
3-
from urllib import request
43
import numpy
54
import os
65
from PIL import Image

0 commit comments

Comments
 (0)