Skip to content

Commit d7969cb

Browse files
authored
Replace print with logging (#6138)
* Replace print with logging * nit * nit * nit * nit * nit * nit
1 parent bddb026 commit d7969cb

File tree

22 files changed

+49
-45
lines changed

22 files changed

+49
-45
lines changed

.ci/update_windows/update.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def pull(repo, remote_name='origin', branch='master'):
2828

2929
if repo.index.conflicts is not None:
3030
for conflict in repo.index.conflicts:
31-
print('Conflicts found in:', conflict[0].path)
31+
print('Conflicts found in:', conflict[0].path) # noqa: T201
3232
raise AssertionError('Conflicts, ahhhhh!!')
3333

3434
user = repo.default_signature
@@ -49,18 +49,18 @@ def pull(repo, remote_name='origin', branch='master'):
4949
repo = pygit2.Repository(repo_path)
5050
ident = pygit2.Signature('comfyui', 'comfy@ui')
5151
try:
52-
print("stashing current changes")
52+
print("stashing current changes") # noqa: T201
5353
repo.stash(ident)
5454
except KeyError:
55-
print("nothing to stash")
55+
print("nothing to stash") # noqa: T201
5656
backup_branch_name = 'backup_branch_{}'.format(datetime.today().strftime('%Y-%m-%d_%H_%M_%S'))
57-
print("creating backup branch: {}".format(backup_branch_name))
57+
print("creating backup branch: {}".format(backup_branch_name)) # noqa: T201
5858
try:
5959
repo.branches.local.create(backup_branch_name, repo.head.peel())
6060
except:
6161
pass
6262

63-
print("checking out master branch")
63+
print("checking out master branch") # noqa: T201
6464
branch = repo.lookup_branch('master')
6565
if branch is None:
6666
ref = repo.lookup_reference('refs/remotes/origin/master')
@@ -72,7 +72,7 @@ def pull(repo, remote_name='origin', branch='master'):
7272
ref = repo.lookup_reference(branch.name)
7373
repo.checkout(ref)
7474

75-
print("pulling latest changes")
75+
print("pulling latest changes") # noqa: T201
7676
pull(repo)
7777

7878
if "--stable" in sys.argv:
@@ -94,7 +94,7 @@ def latest_tag(repo):
9494
if latest_tag is not None:
9595
repo.checkout(latest_tag)
9696

97-
print("Done!")
97+
print("Done!") # noqa: T201
9898

9999
self_update = True
100100
if len(sys.argv) > 2:

app/user_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def __init__(self):
3838
if not os.path.exists(user_directory):
3939
os.makedirs(user_directory, exist_ok=True)
4040
if not args.multi_user:
41-
print("****** User settings have been changed to be stored on the server instead of browser storage. ******")
42-
print("****** For multi-user setups add the --multi-user CLI argument to enable multiple user profiles. ******")
41+
logging.warning("****** User settings have been changed to be stored on the server instead of browser storage. ******")
42+
logging.warning("****** For multi-user setups add the --multi-user CLI argument to enable multiple user profiles. ******")
4343

4444
if args.multi_user:
4545
if os.path.isfile(self.get_users_file()):

comfy/cldm/cldm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def __init__(
160160
if isinstance(self.num_classes, int):
161161
self.label_emb = nn.Embedding(num_classes, time_embed_dim)
162162
elif self.num_classes == "continuous":
163-
print("setting up linear c_adm embedding layer")
164163
self.label_emb = nn.Linear(1, time_embed_dim)
165164
elif self.num_classes == "sequential":
166165
assert adm_in_channels is not None

comfy/extra_samplers/uni_pc.py

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

33
import torch
44
import math
5+
import logging
56

67
from tqdm.auto import trange
78

@@ -474,7 +475,7 @@ def multistep_uni_pc_update(self, x, model_prev_list, t_prev_list, t, order, **k
474475
return self.multistep_uni_pc_vary_update(x, model_prev_list, t_prev_list, t, order, **kwargs)
475476

476477
def multistep_uni_pc_vary_update(self, x, model_prev_list, t_prev_list, t, order, use_corrector=True):
477-
print(f'using unified predictor-corrector with order {order} (solver type: vary coeff)')
478+
logging.info(f'using unified predictor-corrector with order {order} (solver type: vary coeff)')
478479
ns = self.noise_schedule
479480
assert order <= len(model_prev_list)
480481

@@ -518,7 +519,6 @@ def multistep_uni_pc_vary_update(self, x, model_prev_list, t_prev_list, t, order
518519
A_p = C_inv_p
519520

520521
if use_corrector:
521-
print('using corrector')
522522
C_inv = torch.linalg.inv(C)
523523
A_c = C_inv
524524

comfy/hooks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import torch
66
import numpy as np
77
import itertools
8+
import logging
89

910
if TYPE_CHECKING:
1011
from comfy.model_patcher import ModelPatcher, PatcherInjection
@@ -575,7 +576,7 @@ def load_hook_lora_for_models(model: 'ModelPatcher', clip: 'CLIP', lora: dict[st
575576
k1 = set(k1)
576577
for x in loaded:
577578
if (x not in k) and (x not in k1):
578-
print(f"NOT LOADED {x}")
579+
logging.warning(f"NOT LOADED {x}")
579580
return (new_modelpatcher, new_clip, hook_group)
580581

581582
def _combine_hooks_from_values(c_dict: dict[str, HookGroup], values: dict[str, HookGroup], cache: dict[tuple[HookGroup, HookGroup], HookGroup]):

comfy/ldm/aura/mmdit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@ def extend_pe(self, init_dim=(16, 16), target_dim=(64, 64)):
381381
pe_new = pe_as_2d.squeeze(0).permute(1, 2, 0).flatten(0, 1)
382382
self.positional_encoding.data = pe_new.unsqueeze(0).contiguous()
383383
self.h_max, self.w_max = target_dim
384-
print("PE extended to", target_dim)
385384

386385
def pe_selection_index_based_on_dim(self, h, w):
387386
h_p, w_p = h // self.patch_size, w // self.patch_size

comfy/ldm/modules/diffusionmodules/util.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
import math
12+
import logging
1213
import torch
1314
import torch.nn as nn
1415
import numpy as np
@@ -130,7 +131,7 @@ def make_ddim_timesteps(ddim_discr_method, num_ddim_timesteps, num_ddpm_timestep
130131
# add one to get the final alpha values right (the ones from first scale to data during sampling)
131132
steps_out = ddim_timesteps + 1
132133
if verbose:
133-
print(f'Selected timesteps for ddim sampler: {steps_out}')
134+
logging.info(f'Selected timesteps for ddim sampler: {steps_out}')
134135
return steps_out
135136

136137

@@ -142,8 +143,8 @@ def make_ddim_sampling_parameters(alphacums, ddim_timesteps, eta, verbose=True):
142143
# according the the formula provided in https://arxiv.org/abs/2010.02502
143144
sigmas = eta * np.sqrt((1 - alphas_prev) / (1 - alphas) * (1 - alphas / alphas_prev))
144145
if verbose:
145-
print(f'Selected alphas for ddim sampler: a_t: {alphas}; a_(t-1): {alphas_prev}')
146-
print(f'For the chosen value of eta, which is {eta}, '
146+
logging.info(f'Selected alphas for ddim sampler: a_t: {alphas}; a_(t-1): {alphas_prev}')
147+
logging.info(f'For the chosen value of eta, which is {eta}, '
147148
f'this results in the following sigma_t schedule for ddim sampler {sigmas}')
148149
return sigmas, alphas, alphas_prev
149150

comfy/ldm/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
import logging
23

34
import torch
45
from torch import optim
@@ -23,7 +24,7 @@ def log_txt_as_img(wh, xc, size=10):
2324
try:
2425
draw.text((0, 0), lines, fill="black", font=font)
2526
except UnicodeEncodeError:
26-
print("Cant encode string for logging. Skipping.")
27+
logging.warning("Cant encode string for logging. Skipping.")
2728

2829
txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
2930
txts.append(txt)
@@ -65,7 +66,7 @@ def mean_flat(tensor):
6566
def count_params(model, verbose=False):
6667
total_params = sum(p.numel() for p in model.parameters())
6768
if verbose:
68-
print(f"{model.__class__.__name__} has {total_params*1.e-6:.2f} M params.")
69+
logging.info(f"{model.__class__.__name__} has {total_params*1.e-6:.2f} M params.")
6970
return total_params
7071

7172

comfy/model_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ def concat_cond(self, **kwargs):
770770
mask = torch.ones_like(noise)[:, :1]
771771

772772
mask = torch.mean(mask, dim=1, keepdim=True)
773-
print(mask.shape)
774773
mask = utils.common_upscale(mask.to(device), noise.shape[-1] * 8, noise.shape[-2] * 8, "bilinear", "center")
775774
mask = mask.view(mask.shape[0], mask.shape[2] // 8, 8, mask.shape[3] // 8, 8).permute(0, 2, 4, 1, 3).reshape(mask.shape[0], -1, mask.shape[2] // 8, mask.shape[3] // 8)
776775
mask = utils.resize_to_batch_size(mask, noise.shape[0])

comfy/model_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def unload_all_models():
10841084

10851085

10861086
def resolve_lowvram_weight(weight, model, key): #TODO: remove
1087-
print("WARNING: The comfy.model_management.resolve_lowvram_weight function will be removed soon, please stop using it.")
1087+
logging.warning("The comfy.model_management.resolve_lowvram_weight function will be removed soon, please stop using it.")
10881088
return weight
10891089

10901090
#TODO: might be cleaner to put this somewhere else

0 commit comments

Comments
 (0)