Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint unused import #5973

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[MESSAGES CONTROL]
disable=all
enable=eval-used
enable=eval-used, unused-import
2 changes: 0 additions & 2 deletions comfy/cldm/cldm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
#and modified

import torch
import torch as th
import torch.nn as nn

from ..ldm.modules.diffusionmodules.util import (
zero_module,
timestep_embedding,
)

Expand Down
2 changes: 0 additions & 2 deletions comfy/cldm/dit_embedder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import math
from typing import List, Optional, Tuple

import numpy as np
import torch
import torch.nn as nn
from einops import rearrange
from torch import Tensor

from comfy.ldm.modules.diffusionmodules.mmdit import DismantledBlock, PatchEmbed, VectorEmbedder, TimestepEmbedder, get_2d_sincos_pos_embed_torch
Expand Down
2 changes: 1 addition & 1 deletion comfy/cldm/mmdit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from typing import Dict, Optional
from typing import Optional
import comfy.ldm.modules.diffusionmodules.mmdit

class ControlNet(comfy.ldm.modules.diffusionmodules.mmdit.MMDiT):
Expand Down
3 changes: 1 addition & 2 deletions comfy/extra_samplers/uni_pc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#code taken from: https://github.com/wl-zhao/UniPC and modified

import torch
import torch.nn.functional as F
import math

from tqdm.auto import trange, tqdm
from tqdm.auto import trange


class NoiseScheduleVP:
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/audio/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import torch
from torch import nn
from typing import Literal, Dict, Any
from typing import Literal
import math
import comfy.ops
ops = comfy.ops.disable_weight_init
Expand Down
4 changes: 2 additions & 2 deletions comfy/ldm/audio/embedders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import torch
import torch.nn as nn
from torch import Tensor, einsum
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union
from torch import Tensor
from typing import List, Union
from einops import rearrange
import math
import comfy.ops
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/cascade/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

import torch
import torchvision
from torch import nn
from .common import LayerNorm2d_op
Expand Down
4 changes: 1 addition & 3 deletions comfy/ldm/flux/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from torch import Tensor, nn
from einops import rearrange, repeat

from .layers import (DoubleStreamBlock, EmbedND, LastLayer,
MLPEmbedder, SingleStreamBlock,
timestep_embedding)
from .layers import (timestep_embedding)

from .model import Flux
import comfy.ldm.common_dit
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/genmo/joint_model/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#original code from https://github.com/genmoai/models under apache 2.0 license
#adapted to ComfyUI

from typing import Optional, Tuple
from typing import Optional

import torch
import torch.nn as nn
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/genmo/vae/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#original code from https://github.com/genmoai/models under apache 2.0 license
#adapted to ComfyUI

from typing import Callable, List, Optional, Tuple, Union
from typing import List, Optional, Tuple, Union
from functools import partial
import math

Expand Down
7 changes: 0 additions & 7 deletions comfy/ldm/hydit/controlnet.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
from typing import Any, Optional

import torch
import torch.nn as nn
import torch.nn.functional as F

from torch.utils import checkpoint

from comfy.ldm.modules.diffusionmodules.mmdit import (
Mlp,
TimestepEmbedder,
PatchEmbed,
RMSNorm,
)
from comfy.ldm.modules.diffusionmodules.util import timestep_embedding
from .poolers import AttentionPool

import comfy.latent_formats
from .models import HunYuanDiTBlock, calc_rope

from .posemb_layers import get_2d_rotary_pos_embed, get_fill_resize_and_crop


class HunYuanControlNet(nn.Module):
Expand Down
2 changes: 0 additions & 2 deletions comfy/ldm/hydit/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Any

import torch
import torch.nn as nn
import torch.nn.functional as F

import comfy.ops
from comfy.ldm.modules.diffusionmodules.mmdit import Mlp, TimestepEmbedder, PatchEmbed, RMSNorm
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/hydit/poolers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from comfy.ldm.modules.attention import optimized_attention
import comfy.ops

Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/lightricks/vae/causal_video_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import partial
import math
from einops import rearrange
from typing import Any, Mapping, Optional, Tuple, Union, List
from typing import Optional, Tuple, Union
from .conv_nd_factory import make_conv_nd, make_linear_nd
from .pixel_norm import PixelNorm

Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/lightricks/vae/conv_nd_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Tuple, Union

import torch

from .dual_conv3d import DualConv3d
from .causal_conv3d import CausalConv3d
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/models/autoencoder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from contextlib import contextmanager
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, Tuple, Union

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

Expand Down
2 changes: 0 additions & 2 deletions comfy/ldm/modules/diffusionmodules/mmdit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging
import math
from typing import Dict, Optional, List

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/modules/diffusionmodules/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import torch
import torch.nn as nn
import numpy as np
from typing import Optional, Any
import logging

from comfy import model_management
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/modules/diffusionmodules/openaimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .util import (
checkpoint,
avg_pool_nd,
zero_module,
timestep_embedding,
AlphaBlender,
)
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/modules/diffusionmodules/upscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from functools import partial

from .util import extract_into_tensor, make_beta_schedule
from comfy.ldm.util import default


class AbstractLowScaleModel(nn.Module):
Expand Down
1 change: 0 additions & 1 deletion comfy/ldm/modules/diffusionmodules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# thanks!


import os
import math
import torch
import torch.nn as nn
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/modules/temporal_ae.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
from typing import Callable, Iterable, Union
from typing import Iterable, Union

import torch
from einops import rearrange, repeat
Expand Down
1 change: 0 additions & 1 deletion comfy/sampler_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations
import uuid
import torch
import comfy.model_management
import comfy.conds
import comfy.utils
Expand Down
1 change: 0 additions & 1 deletion comfy/text_encoders/spiece_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import torch

class SPieceTokenizer:
Expand Down
3 changes: 1 addition & 2 deletions comfy_extras/nodes_advanced_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import comfy.utils
import torch
import numpy as np
from tqdm.auto import trange, tqdm
import math
from tqdm.auto import trange


@torch.no_grad()
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_clip_sdxl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import torch
from nodes import MAX_RESOLUTION

class CLIPTextEncodeSDXLRefiner:
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_compositing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy as np
import torch
import comfy.utils
from enum import Enum
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections.abc import Iterable

if TYPE_CHECKING:
from comfy.model_patcher import ModelPatcher
from comfy.sd import CLIP

import comfy.hooks
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_model_advanced.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import folder_paths
import comfy.sd
import comfy.model_sampling
import comfy.latent_formats
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_model_downscale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import torch
import comfy.utils

class PatchModelAddDownscale:
Expand Down
1 change: 0 additions & 1 deletion comfy_extras/nodes_upscale_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import logging
from spandrel import ModelLoader, ImageModelDescriptor
from comfy import model_management
Expand Down
4 changes: 1 addition & 3 deletions custom_nodes/websocket_image_save.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from PIL import Image, ImageOps
from io import BytesIO
from PIL import Image
import numpy as np
import struct
import comfy.utils
import time

Expand Down
1 change: 0 additions & 1 deletion execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from comfy_execution.graph_utils import is_link, GraphBuilder
from comfy_execution.caching import HierarchicalCache, LRUCache, CacheKeySetInputSignature, CacheKeySetID
from comfy_execution.validation import validate_node_input
from comfy.cli_args import args

class ExecutionResult(Enum):
SUCCESS = 0
Expand Down
36 changes: 20 additions & 16 deletions fix_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import logging


torch_spec = importlib.util.find_spec("torch")
for folder in torch_spec.submodule_search_locations:
lib_folder = os.path.join(folder, "lib")
test_file = os.path.join(lib_folder, "fbgemm.dll")
dest = os.path.join(lib_folder, "libomp140.x86_64.dll")
if os.path.exists(dest):
break

with open(test_file, 'rb') as f:
contents = f.read()
if b"libomp140.x86_64.dll" not in contents:
def fix_pytorch_libomp():
"""
Fix PyTorch libomp DLL issue on Windows by copying the correct DLL file if needed.
"""
torch_spec = importlib.util.find_spec("torch")
for folder in torch_spec.submodule_search_locations:
lib_folder = os.path.join(folder, "lib")
test_file = os.path.join(lib_folder, "fbgemm.dll")
dest = os.path.join(lib_folder, "libomp140.x86_64.dll")
if os.path.exists(dest):
break
try:
mydll = ctypes.cdll.LoadLibrary(test_file)
except FileNotFoundError as e:
logging.warning("Detected pytorch version with libomp issue, patching.")
shutil.copyfile(os.path.join(lib_folder, "libiomp5md.dll"), dest)

with open(test_file, "rb") as f:
contents = f.read()
if b"libomp140.x86_64.dll" not in contents:
break
try:
mydll = ctypes.cdll.LoadLibrary(test_file)
except FileNotFoundError as e:
logging.warning("Detected pytorch version with libomp issue, patching.")
shutil.copyfile(os.path.join(lib_folder, "libiomp5md.dll"), dest)
4 changes: 2 additions & 2 deletions folder_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import mimetypes
import logging
from typing import Set, List, Dict, Tuple, Literal
from typing import Literal
from collections.abc import Collection

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

def filter_files_content_types(files: List[str], content_types: Literal["image", "video", "audio"]) -> List[str]:
def filter_files_content_types(files: list[str], content_types: Literal["image", "video", "audio"]) -> list[str]:
"""
Example:
files = os.listdir(folder_paths.get_input_directory())
Expand Down
2 changes: 0 additions & 2 deletions latent_preview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import torch
from PIL import Image
import struct
import numpy as np
from comfy.cli_args import args, LatentPreviewMethod
from comfy.taesd.taesd import TAESD
import comfy.model_management
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def execute_script(script_path):

if args.windows_standalone_build:
try:
import fix_torch
from fix_torch import fix_pytorch_libomp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert module level execution to a function call here to avoid the unused import.

fix_pytorch_libomp()
except:
pass

Expand Down
3 changes: 1 addition & 2 deletions script_examples/basic_api_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
from urllib import request, parse
import random
from urllib import request

#This is the ComfyUI api prompt format.

Expand Down
1 change: 0 additions & 1 deletion tests/inference/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from copy import deepcopy
from io import BytesIO
from urllib import request
import numpy
import os
from PIL import Image
Expand Down
Loading