efficiency-nodes-comfyui icon indicating copy to clipboard operation
efficiency-nodes-comfyui copied to clipboard

Refactor and Optimize Codebase for latest ComfyUI

Open toxicwind opened this issue 1 year ago • 1 comments

This pull request aims to enhance the codebase by improving code organization, readability, and maintainability. The changes made are as follows:

  1. 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.
  2. Refactored Functions:

    • Refactored functions like adjust_tensor_shape, expand, and bounded_modulo for improved efficiency and readability.
  3. calc_cond Function:

    • Simplified and improved readability using dictionary comprehension.
    • Enhanced the code for determining 'orig_len' and selecting conditions.
  4. catenate_conds and subscript_cond Functions:

    • Simplified and made more concise for better readability.
  5. pad_cond Function:

    • Modified to use F.pad for efficient tensor padding.
  6. CFGDenoiser Class:

    • Introduced methods like prepare_inputs, prepare_cond, apply_model, and post_process for modularity and readability.
    • Eliminated redundant code segments for conciseness and clarity.
  7. 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.
  8. SDKSampler Class:

    • Introduced the set_model_wrap method to set the model_wrap attribute for improved organization.
    • Modified the constructor to use the set_model_wrap method.

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.

toxicwind avatar Nov 05 '23 07:11 toxicwind

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'

h3clikejava avatar Nov 08 '23 05:11 h3clikejava