JarvisLabs commited on
Commit
4d012e7
1 Parent(s): c490d71

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +1 -53
utils.py CHANGED
@@ -3,19 +3,12 @@ import os
3
  import random
4
  import numpy as np
5
  import json
6
- import torch
7
  import uuid
8
  from PIL import Image, PngImagePlugin
9
  from datetime import datetime
10
  from dataclasses import dataclass
11
  from typing import Callable, Dict, Optional, Tuple
12
- from diffusers import (
13
- DDIMScheduler,
14
- DPMSolverMultistepScheduler,
15
- DPMSolverSinglestepScheduler,
16
- EulerAncestralDiscreteScheduler,
17
- EulerDiscreteScheduler,
18
- )
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
 
@@ -32,14 +25,6 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
32
  return seed
33
 
34
 
35
- def seed_everything(seed: int) -> torch.Generator:
36
- torch.manual_seed(seed)
37
- torch.cuda.manual_seed_all(seed)
38
- np.random.seed(seed)
39
- generator = torch.Generator()
40
- generator.manual_seed(seed)
41
- return generator
42
-
43
 
44
  def parse_aspect_ratio(aspect_ratio: str) -> Optional[Tuple[int, int]]:
45
  if aspect_ratio == "Custom":
@@ -58,24 +43,6 @@ def aspect_ratio_handler(
58
  return width, height
59
 
60
 
61
- def get_scheduler(scheduler_config: Dict, name: str) -> Optional[Callable]:
62
- scheduler_factory_map = {
63
- "DPM++ 2M Karras": lambda: DPMSolverMultistepScheduler.from_config(
64
- scheduler_config, use_karras_sigmas=True
65
- ),
66
- "DPM++ SDE Karras": lambda: DPMSolverSinglestepScheduler.from_config(
67
- scheduler_config, use_karras_sigmas=True
68
- ),
69
- "DPM++ 2M SDE Karras": lambda: DPMSolverMultistepScheduler.from_config(
70
- scheduler_config, use_karras_sigmas=True, algorithm_type="sde-dpmsolver++"
71
- ),
72
- "Euler": lambda: EulerDiscreteScheduler.from_config(scheduler_config),
73
- "Euler a": lambda: EulerAncestralDiscreteScheduler.from_config(
74
- scheduler_config
75
- ),
76
- "DDIM": lambda: DDIMScheduler.from_config(scheduler_config),
77
- }
78
- return scheduler_factory_map.get(name, lambda: None)()
79
 
80
 
81
  def free_memory() -> None:
@@ -107,25 +74,6 @@ def preprocess_prompt(
107
  return formatted_positive, combined_negative
108
 
109
 
110
- def common_upscale(
111
- samples: torch.Tensor,
112
- width: int,
113
- height: int,
114
- upscale_method: str,
115
- ) -> torch.Tensor:
116
- return torch.nn.functional.interpolate(
117
- samples, size=(height, width), mode=upscale_method
118
- )
119
-
120
-
121
- def upscale(
122
- samples: torch.Tensor, upscale_method: str, scale_by: float
123
- ) -> torch.Tensor:
124
- width = round(samples.shape[3] * scale_by)
125
- height = round(samples.shape[2] * scale_by)
126
- return common_upscale(samples, width, height, upscale_method)
127
-
128
-
129
 
130
  def get_random_line_from_file(file_path: str) -> str:
131
  with open(file_path, "r") as file:
 
3
  import random
4
  import numpy as np
5
  import json
 
6
  import uuid
7
  from PIL import Image, PngImagePlugin
8
  from datetime import datetime
9
  from dataclasses import dataclass
10
  from typing import Callable, Dict, Optional, Tuple
11
+
 
 
 
 
 
 
12
 
13
  MAX_SEED = np.iinfo(np.int32).max
14
 
 
25
  return seed
26
 
27
 
 
 
 
 
 
 
 
 
28
 
29
  def parse_aspect_ratio(aspect_ratio: str) -> Optional[Tuple[int, int]]:
30
  if aspect_ratio == "Custom":
 
43
  return width, height
44
 
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
 
48
  def free_memory() -> None:
 
74
  return formatted_positive, combined_negative
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  def get_random_line_from_file(file_path: str) -> str:
79
  with open(file_path, "r") as file: