fix: delete stale pyc + recompile after patching in fixes.py
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Patches applied to x-flux-comfyui for ComfyUI compatibility."""
|
||||
import re
|
||||
import os, glob
|
||||
|
||||
# Fix 1: xflux DoubleStreamBlock.forward doesn't accept attn_mask/transformer_options
|
||||
# ComfyUI calls block(..., attn_mask=attn_mask, transformer_options=...) which fails
|
||||
path1 = '/app/custom_nodes/x-flux-comfyui/xflux/src/flux/modules/layers.py'
|
||||
with open(path1) as f:
|
||||
c = f.read()
|
||||
@@ -15,27 +14,23 @@ with open(path1, 'w') as f:
|
||||
print('Fix 1 applied: DoubleStreamBlock.forward accepts attn_mask')
|
||||
|
||||
# Fix 2: IPProcessor.forward sdpa dtype mismatch (ip_query=float32, ip_key/value=bfloat16)
|
||||
# Caused by projection layers loading in bfloat16 while img tensor stays float32
|
||||
path2 = '/app/custom_nodes/x-flux-comfyui/layers.py'
|
||||
with open(path2) as f:
|
||||
c = f.read()
|
||||
old2 = ''' ip_attention = F.scaled_dot_product_attention(
|
||||
ip_query,
|
||||
ip_key,
|
||||
ip_value,
|
||||
dropout_p=0.0,
|
||||
is_causal=False
|
||||
)'''
|
||||
new2 = ''' ip_attention = F.scaled_dot_product_attention(
|
||||
ip_query,
|
||||
ip_key.to(ip_query.dtype),
|
||||
ip_value.to(ip_query.dtype),
|
||||
dropout_p=0.0,
|
||||
is_causal=False
|
||||
)'''
|
||||
old2 = ' ip_attention = F.scaled_dot_product_attention(\n ip_query, \n ip_key, \n ip_value, \n dropout_p=0.0, \n is_causal=False\n )'
|
||||
new2 = ' ip_attention = F.scaled_dot_product_attention(\n ip_query.float(), \n ip_key.float(), \n ip_value.float(), \n dropout_p=0.0, \n is_causal=False\n )'
|
||||
assert old2 in c, f'Fix 2 pattern not found in {path2}'
|
||||
with open(path2, 'w') as f:
|
||||
f.write(c.replace(old2, new2))
|
||||
print('Fix 2 applied: IPProcessor sdpa dtype cast')
|
||||
print('Fix 2 applied: IPProcessor sdpa cast to float32')
|
||||
|
||||
# Delete all stale .pyc files so Python recompiles from patched .py
|
||||
for pyc in glob.glob('/app/custom_nodes/x-flux-comfyui/**/*.pyc', recursive=True):
|
||||
os.remove(pyc)
|
||||
print(f'Removed stale pyc: {pyc}')
|
||||
|
||||
# Recompile from patched sources
|
||||
import compileall
|
||||
compileall.compile_dir('/app/custom_nodes/x-flux-comfyui', quiet=True)
|
||||
print('Recompiled all x-flux-comfyui sources')
|
||||
print('All fixes applied successfully.')
|
||||
Reference in New Issue
Block a user