Skip to content

Commit

Permalink
run lint rules using latest isort settings
Browse files Browse the repository at this point in the history
  • Loading branch information
deltheil committed Dec 11, 2023
1 parent b44d612 commit 792a0fc
Show file tree
Hide file tree
Showing 109 changed files with 480 additions and 419 deletions.
6 changes: 4 additions & 2 deletions scripts/conversion/convert_diffusers_autoencoder_kl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
from pathlib import Path

import torch
from torch import nn
from diffusers import AutoencoderKL # type: ignore
from refiners.foundationals.latent_diffusion.auto_encoder import LatentDiffusionAutoencoder
from torch import nn

from refiners.fluxion.model_converter import ModelConverter
from refiners.foundationals.latent_diffusion.auto_encoder import LatentDiffusionAutoencoder


class Args(argparse.Namespace):
Expand Down
10 changes: 6 additions & 4 deletions scripts/conversion/convert_diffusers_controlnet.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# pyright: reportPrivateUsage=false
import argparse
from pathlib import Path

import torch
from torch import nn
from diffusers import ControlNetModel # type: ignore
from refiners.fluxion.utils import save_to_safetensors
from torch import nn

from refiners.fluxion.model_converter import ModelConverter
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.latent_diffusion import (
SD1UNet,
SD1ControlnetAdapter,
DPMSolver,
SD1ControlnetAdapter,
SD1UNet,
)


Expand Down
4 changes: 2 additions & 2 deletions scripts/conversion/convert_diffusers_ip_adapter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import argparse
from pathlib import Path
from typing import Any
import argparse

import torch

from refiners.foundationals.latent_diffusion import SD1UNet, SD1IPAdapter, SDXLUNet, SDXLIPAdapter
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.latent_diffusion import SD1IPAdapter, SD1UNet, SDXLIPAdapter, SDXLUNet

# Running:
#
Expand Down
7 changes: 3 additions & 4 deletions scripts/conversion/convert_diffusers_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
from typing import cast

import torch
from diffusers import DiffusionPipeline # type: ignore
from torch import Tensor
from torch.nn.init import zeros_
from torch.nn import Parameter as TorchParameter

from diffusers import DiffusionPipeline # type: ignore
from torch.nn.init import zeros_

import refiners.fluxion.layers as fl
from refiners.fluxion.adapters.lora import Lora, LoraAdapter
from refiners.fluxion.model_converter import ModelConverter
from refiners.fluxion.utils import save_to_safetensors
from refiners.fluxion.adapters.lora import Lora, LoraAdapter
from refiners.foundationals.latent_diffusion import SD1UNet
from refiners.foundationals.latent_diffusion.lora import LoraTarget, lora_targets

Expand Down
6 changes: 4 additions & 2 deletions scripts/conversion/convert_diffusers_t2i_adapter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import argparse
from pathlib import Path

import torch
from torch import nn
from diffusers import T2IAdapter # type: ignore
from refiners.foundationals.latent_diffusion.t2i_adapter import ConditionEncoder, ConditionEncoderXL
from torch import nn

from refiners.fluxion.model_converter import ModelConverter
from refiners.foundationals.latent_diffusion.t2i_adapter import ConditionEncoder, ConditionEncoderXL

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Convert a pretrained diffusers T2I-Adapter model to refiners")
Expand Down
4 changes: 3 additions & 1 deletion scripts/conversion/convert_diffusers_unet.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import argparse
from pathlib import Path

import torch
from diffusers import UNet2DConditionModel # type: ignore
from torch import nn

from refiners.fluxion.model_converter import ModelConverter
from diffusers import UNet2DConditionModel # type: ignore
from refiners.foundationals.latent_diffusion import SD1UNet, SDXLUNet


Expand Down
2 changes: 2 additions & 0 deletions scripts/conversion/convert_informative_drawings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import argparse
from typing import TYPE_CHECKING, cast

import torch
from torch import nn

from refiners.fluxion.model_converter import ModelConverter
from refiners.foundationals.latent_diffusion.preprocessors.informative_drawings import InformativeDrawings

Expand Down
14 changes: 8 additions & 6 deletions scripts/conversion/convert_refiners_lora_to_sdwebui.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import argparse
from functools import partial

from convert_diffusers_unet import Args as UnetConversionArgs, setup_converter as convert_unet
from convert_transformers_clip_text_model import (
Args as TextEncoderConversionArgs,
setup_converter as convert_text_encoder,
)
from torch import Tensor

import refiners.fluxion.layers as fl
from refiners.fluxion.utils import (
load_from_safetensors,
load_metadata_from_safetensors,
save_to_safetensors,
)
from convert_diffusers_unet import setup_converter as convert_unet, Args as UnetConversionArgs
from convert_transformers_clip_text_model import (
setup_converter as convert_text_encoder,
Args as TextEncoderConversionArgs,
)
from refiners.foundationals.clip.text_encoder import CLIPTextEncoderL
from refiners.foundationals.latent_diffusion import SD1UNet
from refiners.foundationals.latent_diffusion.lora import LoraTarget
import refiners.fluxion.layers as fl


def get_unet_mapping(source_path: str) -> dict[str, str]:
Expand Down
12 changes: 6 additions & 6 deletions scripts/conversion/convert_segment_anything.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import argparse
import types
from typing import Any, Callable, cast

import torch
import torch.nn as nn
from segment_anything import build_sam_vit_h # type: ignore
from segment_anything.modeling.common import LayerNorm2d # type: ignore
from torch import Tensor

import refiners.fluxion.layers as fl
from refiners.fluxion.model_converter import ModelConverter
from refiners.fluxion.utils import manual_seed, save_to_safetensors
from refiners.foundationals.segment_anything.image_encoder import SAMViTH
from refiners.foundationals.segment_anything.prompt_encoder import PointEncoder, MaskEncoder

from segment_anything import build_sam_vit_h # type: ignore
from segment_anything.modeling.common import LayerNorm2d # type: ignore

from refiners.foundationals.segment_anything.mask_decoder import MaskDecoder
from refiners.foundationals.segment_anything.prompt_encoder import MaskEncoder, PointEncoder


class FacebookSAM(nn.Module):
Expand Down Expand Up @@ -134,9 +133,10 @@ def convert_mask_decoder(mask_decoder: nn.Module) -> dict[str, Tensor]:
point_embedding = torch.randn(1, 3, 256)
mask_embedding = torch.randn(1, 256, 64, 64)

import refiners.fluxion.layers as fl
from segment_anything.modeling.common import LayerNorm2d # type: ignore

import refiners.fluxion.layers as fl

assert issubclass(LayerNorm2d, nn.Module)
custom_layers = {LayerNorm2d: fl.LayerNorm2d}

Expand Down
10 changes: 6 additions & 4 deletions scripts/conversion/convert_transformers_clip_image_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import argparse
from pathlib import Path

import torch
from torch import nn
from refiners.fluxion.model_converter import ModelConverter
from transformers import CLIPVisionModelWithProjection # type: ignore
from refiners.foundationals.clip.image_encoder import CLIPImageEncoder
from refiners.fluxion.utils import save_to_safetensors
import torch

import refiners.fluxion.layers as fl
from refiners.fluxion.model_converter import ModelConverter
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.clip.image_encoder import CLIPImageEncoder


class Args(argparse.Namespace):
Expand Down
10 changes: 6 additions & 4 deletions scripts/conversion/convert_transformers_clip_text_model.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import argparse
from pathlib import Path
from typing import cast

from torch import nn
from refiners.fluxion.model_converter import ModelConverter
from transformers import CLIPTextModelWithProjection # type: ignore
from refiners.foundationals.clip.text_encoder import CLIPTextEncoder, CLIPTextEncoderL, CLIPTextEncoderG

import refiners.fluxion.layers as fl
from refiners.fluxion.model_converter import ModelConverter
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.clip.text_encoder import CLIPTextEncoder, CLIPTextEncoderG, CLIPTextEncoderL
from refiners.foundationals.clip.tokenizer import CLIPTokenizer
from refiners.foundationals.latent_diffusion.stable_diffusion_xl.text_encoder import DoubleTextEncoder
from refiners.fluxion.utils import save_to_safetensors
import refiners.fluxion.layers as fl


class Args(argparse.Namespace):
Expand Down
13 changes: 7 additions & 6 deletions scripts/training/finetune-ldm-lora.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import random
from typing import Any
from pydantic import BaseModel

from loguru import logger
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.latent_diffusion.lora import LoraTarget, LoraAdapter, MODELS, lora_targets
import refiners.fluxion.layers as fl
from pydantic import BaseModel
from torch import Tensor
from torch.utils.data import Dataset

import refiners.fluxion.layers as fl
from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.latent_diffusion.lora import MODELS, LoraAdapter, LoraTarget, lora_targets
from refiners.training_utils.callback import Callback
from refiners.training_utils.latent_diffusion import (
FinetuneLatentDiffusionConfig,
LatentDiffusionConfig,
LatentDiffusionTrainer,
TextEmbeddingLatentsBatch,
TextEmbeddingLatentsDataset,
LatentDiffusionTrainer,
LatentDiffusionConfig,
)


Expand Down
14 changes: 7 additions & 7 deletions scripts/training/finetune-ldm-textual-inversion.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import random
from typing import Any
from pydantic import BaseModel

from loguru import logger
from pydantic import BaseModel
from torch import Tensor, randn
from torch.utils.data import Dataset
from torch import randn, Tensor
import random

from refiners.fluxion.utils import save_to_safetensors
from refiners.foundationals.clip.concepts import ConceptExtender, EmbeddingExtender
from refiners.foundationals.clip.text_encoder import CLIPTextEncoder, TokenEncoder
from refiners.foundationals.clip.tokenizer import CLIPTokenizer
from refiners.fluxion.utils import save_to_safetensors
from refiners.training_utils.callback import Callback
from refiners.training_utils.latent_diffusion import (
FinetuneLatentDiffusionConfig,
TextEmbeddingLatentsBatch,
LatentDiffusionTrainer,
LatentDiffusionConfig,
LatentDiffusionTrainer,
TextEmbeddingLatentsBatch,
TextEmbeddingLatentsDataset,
)


IMAGENET_TEMPLATES_SMALL = [
"a photo of a {}",
"a rendering of a {}",
Expand Down
2 changes: 1 addition & 1 deletion src/refiners/fluxion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from refiners.fluxion.utils import save_to_safetensors, load_from_safetensors, norm, manual_seed, pad
from refiners.fluxion.utils import load_from_safetensors, manual_seed, norm, pad, save_to_safetensors

__all__ = ["norm", "manual_seed", "save_to_safetensors", "load_from_safetensors", "pad"]
4 changes: 2 additions & 2 deletions src/refiners/fluxion/adapters/adapter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import refiners.fluxion.layers as fl
from typing import Any, Generic, TypeVar, Iterator
from typing import Any, Generic, Iterator, TypeVar

import refiners.fluxion.layers as fl

T = TypeVar("T", bound=fl.Module)
TAdapter = TypeVar("TAdapter", bound="Adapter[Any]") # Self (see PEP 673)
Expand Down
10 changes: 5 additions & 5 deletions src/refiners/fluxion/adapters/lora.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Iterable, Generic, TypeVar, Any

import refiners.fluxion.layers as fl
from refiners.fluxion.adapters.adapter import Adapter
from typing import Any, Generic, Iterable, TypeVar

from torch import Tensor, device as Device, dtype as DType
from torch.nn import Parameter as TorchParameter
from torch.nn.init import zeros_, normal_
from torch.nn.init import normal_, zeros_

import refiners.fluxion.layers as fl
from refiners.fluxion.adapters.adapter import Adapter

T = TypeVar("T", bound=fl.Chain)
TLoraAdapter = TypeVar("TLoraAdapter", bound="LoraAdapter[Any]") # Self (see PEP 673)
Expand Down
1 change: 1 addition & 0 deletions src/refiners/fluxion/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any

from torch import Tensor

Context = dict[str, Any]
Expand Down
56 changes: 28 additions & 28 deletions src/refiners/fluxion/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
from refiners.fluxion.layers.activations import GLU, SiLU, ReLU, ApproximateGeLU, GeLU, Sigmoid
from refiners.fluxion.layers.norm import LayerNorm, GroupNorm, LayerNorm2d, InstanceNorm2d
from refiners.fluxion.layers.activations import GLU, ApproximateGeLU, GeLU, ReLU, Sigmoid, SiLU
from refiners.fluxion.layers.attentions import Attention, SelfAttention, SelfAttention2d
from refiners.fluxion.layers.basics import (
Identity,
View,
Buffer,
Chunk,
Cos,
Flatten,
Unflatten,
Transpose,
GetArg,
Identity,
Multiply,
Parameter,
Permute,
Reshape,
Squeeze,
Unsqueeze,
Slicing,
Sin,
Cos,
Chunk,
Multiply,
Slicing,
Squeeze,
Transpose,
Unbind,
Parameter,
Buffer,
Unflatten,
Unsqueeze,
View,
)
from refiners.fluxion.layers.chain import (
Breakpoint,
Chain,
Concatenate,
Distribute,
Lambda,
Sum,
Matmul,
Parallel,
Passthrough,
Residual,
Return,
Chain,
UseContext,
SetContext,
Parallel,
Distribute,
Passthrough,
Breakpoint,
Concatenate,
Matmul,
Sum,
UseContext,
)
from refiners.fluxion.layers.conv import Conv2d, ConvTranspose2d
from refiners.fluxion.layers.converter import Converter
from refiners.fluxion.layers.embedding import Embedding
from refiners.fluxion.layers.linear import Linear, MultiLinear
from refiners.fluxion.layers.module import Module, WeightedModule, ContextModule
from refiners.fluxion.layers.maxpool import MaxPool1d, MaxPool2d
from refiners.fluxion.layers.module import ContextModule, Module, WeightedModule
from refiners.fluxion.layers.norm import GroupNorm, InstanceNorm2d, LayerNorm, LayerNorm2d
from refiners.fluxion.layers.padding import ReflectionPad2d
from refiners.fluxion.layers.pixelshuffle import PixelUnshuffle
from refiners.fluxion.layers.sampling import Downsample, Upsample, Interpolate
from refiners.fluxion.layers.embedding import Embedding
from refiners.fluxion.layers.converter import Converter
from refiners.fluxion.layers.maxpool import MaxPool1d, MaxPool2d
from refiners.fluxion.layers.sampling import Downsample, Interpolate, Upsample

__all__ = [
"Embedding",
Expand Down
Loading

0 comments on commit 792a0fc

Please sign in to comment.