efficiency-nodes-comfyui
efficiency-nodes-comfyui copied to clipboard
Refactor and Optimize Codebase for latest ComfyUI
This pull request aims to enhance the codebase by improving code organization, readability, and maintainability. The changes made are as follows:
-
Code Organization and Style:
- Sorted imported modules alphabetically.
- Added type hints for function parameters and return values.
- Removed unnecessary imports for code cleanliness.
- Formatted the code according to PEP 8 style guidelines.
-
Refactored Functions:
- Refactored functions like
adjust_tensor_shape
,expand
, andbounded_modulo
for improved efficiency and readability.
- Refactored functions like
-
calc_cond
Function:- Simplified and improved readability using dictionary comprehension.
- Enhanced the code for determining 'orig_len' and selecting conditions.
-
catenate_conds
andsubscript_cond
Functions:- Simplified and made more concise for better readability.
-
pad_cond
Function:- Modified to use
F.pad
for efficient tensor padding.
- Modified to use
-
CFGDenoiser
Class:- Introduced methods like
prepare_inputs
,prepare_cond
,apply_model
, andpost_process
for modularity and readability. - Eliminated redundant code segments for conciseness and clarity.
- Introduced methods like
-
CFGNoisePredictor
Class:- Refactored the
apply_model
method for readability and modularity. - Introduced helper methods for efficient condition preparation.
- Made the
txt2img_image_conditioning
method static for better organization.
- Refactored the
-
SDKSampler
Class:- Introduced the
set_model_wrap
method to set themodel_wrap
attribute for improved organization. - Modified the constructor to use the
set_model_wrap
method.
- Introduced the
These changes aim to improve code quality and make it more readable and maintainable while preserving the original functionality of the code. The code remains functionally intact, but the enhancements result in a cleaner, more organized, and better-documented codebase.
ERROR:root:!!! Exception during processing !!! ERROR:root:Traceback (most recent call last): File "/home/h3c/Documents/ComfyUI/execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/home/h3c/Documents/ComfyUI/execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "/home/h3c/Documents/ComfyUI/execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "/home/h3c/Documents/ComfyUI/custom_nodes/efficiency-nodes-comfyui/efficiency_nodes.py", line 702, in sample samples, images, gifs, preview = process_latent_image(model, seed, steps, cfg, sampler_name, scheduler, File "/home/h3c/Documents/ComfyUI/custom_nodes/efficiency-nodes-comfyui/efficiency_nodes.py", line 505, in process_latent_image positive_hash = tensor_to_hash(positive[0][0]) File "/home/h3c/Documents/ComfyUI/custom_nodes/efficiency-nodes-comfyui/tsc_utils.py", line 96, in tensor_to_hash byte_repr = tensor.cpu().numpy().tobytes() # Convert tensor to bytes AttributeError: 'NoneType' object has no attribute 'cpu'