[Partner Nodes] ByteDance: virtual portrait library for regular images#13638
[Partner Nodes] ByteDance: virtual portrait library for regular images#13638Kosinkadink merged 3 commits intomasterfrom
Conversation
…ar images Signed-off-by: bigcat88 <bigcat88@icloud.com>
📝 WalkthroughWalkthroughAdds SHA-256 hashing for image tensors and a helper that uploads images to ComfyAPI, registers them via 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@comfy_api_nodes/nodes_bytedance.py`:
- Around line 284-289: The current image dedup hash computed in the image_hash
line (using hashlib.sha256 on
image.detach().cpu().contiguous().to(torch.float32).numpy().tobytes()) omits the
image shape and can cause collisions for different-shaped arrays with identical
flattened bytes; update the hash computation in the same block (where image_hash
is created, referenced by the variable image and the use of hashlib.sha256) to
also incorporate the image shape (for example by feeding the shape tuple or its
bytes into the hasher before/after the raw bytes) so the resulting hash used in
SeedanceVirtualLibraryCreateAssetRequest is unique to both content and
dimensions.
- Around line 283-289: The synchronous SHA-256 tensor hashing (the image_hash
computation) blocks the event loop; modify ByteDance2ReferenceNode.execute to
offload that work by running the hashing expression inside asyncio.to_thread and
awaiting it before calling sync_op/create request. Specifically, replace the
direct image.detach().cpu().contiguous().to(torch.float32).numpy().tobytes() +
hashlib.sha256(...).hexdigest() computation with an awaited asyncio.to_thread
wrapper that returns the hex digest and assign it to image_hash (keep
upload_image_to_comfyapi call and subsequent
sync_op/SeedanceVirtualLibraryCreateAssetRequest usage unchanged).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f05c165c-9863-44a8-b081-ca12b796b3f8
⛔ Files ignored due to path filters (1)
comfy_api_nodes/apis/bytedance.pyis excluded by!comfy_api_nodes/apis/**
📒 Files selected for processing (1)
comfy_api_nodes/nodes_bytedance.py
Signed-off-by: bigcat88 <bigcat88@icloud.com>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
comfy_api_nodes/nodes_bytedance.py (1)
284-289:⚠️ Potential issue | 🟠 MajorOffload hash computation from the async path.
This new code performs CPU-heavy tensor normalization + NumPy conversion + SHA-256 directly on the event loop. With multiple reference images, it can block concurrent async work. Please move hashing into
asyncio.to_thread(...).Suggested fix
+import asyncio import hashlib- normalized = image.detach().cpu().contiguous().to(torch.float32) - digest = hashlib.sha256() - digest.update(str(tuple(normalized.shape)).encode("utf-8")) - digest.update(b"\0") - digest.update(normalized.numpy().tobytes()) - image_hash = digest.hexdigest() + def _compute_image_hash() -> str: + normalized = image.detach().cpu().contiguous().to(torch.float32) + digest = hashlib.sha256() + digest.update(str(tuple(normalized.shape)).encode("utf-8")) + digest.update(b"\0") + digest.update(normalized.numpy().tobytes()) + return digest.hexdigest() + + image_hash = await asyncio.to_thread(_compute_image_hash)Based on learnings: "if the PR adds new synchronous CPU/IO work inside
async def execute, prefer offloading withasyncio.to_thread(or an equivalent background executor) to avoid blocking the event loop."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@comfy_api_nodes/nodes_bytedance.py` around lines 284 - 289, The CPU-heavy tensor normalization, NumPy conversion and SHA-256 hash must be offloaded from the async path: create a synchronous helper (e.g., compute_image_hash(image)) that performs normalized = image.detach().cpu().contiguous().to(torch.float32), builds the hashlib digest from normalized.numpy().tobytes() and returns the hex digest, then inside async def execute replace the inline hashing code with: image_hash = await asyncio.to_thread(compute_image_hash, image). Ensure the helper name (compute_image_hash), the image_hash variable and the call site in async def execute are updated accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@comfy_api_nodes/nodes_bytedance.py`:
- Around line 284-289: The CPU-heavy tensor normalization, NumPy conversion and
SHA-256 hash must be offloaded from the async path: create a synchronous helper
(e.g., compute_image_hash(image)) that performs normalized =
image.detach().cpu().contiguous().to(torch.float32), builds the hashlib digest
from normalized.numpy().tobytes() and returns the hex digest, then inside async
def execute replace the inline hashing code with: image_hash = await
asyncio.to_thread(compute_image_hash, image). Ensure the helper name
(compute_image_hash), the image_hash variable and the call site in async def
execute are updated accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fecd10b8-e2bf-440f-9684-e01a64524149
📒 Files selected for processing (1)
comfy_api_nodes/nodes_bytedance.py
API Node PR Checklist
Scope
Pricing & Billing
If Need pricing update:
QA
Comms