Skip to content

Commit

Permalink
support for both batch sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
saienduri committed Jul 24, 2024
1 parent 87afa58 commit 71ffc84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions models/turbine_models/custom_models/sd_inference/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ def iree_backend_map(device):

def replace_with_tk_kernels(
flow_dialect_ir,
batch_size
):
kernels = [
"https://raw.githubusercontent.com/nod-ai/sdxl-scripts/main/int8-model/tk_kernels/tk_gemm_fused_16x1024x10240x1280.mlir"
]
if batch_size == 8:
kernels = [
"https://raw.githubusercontent.com/nod-ai/sdxl-scripts/main/int8-model/tk_kernels/tk_gemm_fused_16x1024x10240x1280.mlir"
]
if batch_size == 1:
kernels = [
"https://raw.githubusercontent.com/nod-ai/sdxl-scripts/main/int8-model/tk_kernels/tk_gemm_fused_2x1024x10240x1280.mlir"
]

# Replace all calls to old kernel with new kernel
print("Inserting kernels and updating calls to kernels...")
Expand Down Expand Up @@ -235,7 +241,10 @@ def compile_to_vmfb(
flagset_keywords=[],
debug=False,
add_tk_kernels=False,
batch_size=1,
):
if batch_size != 1 and batch_size != 8:
add_tk_kernels = False
flags = []
if mlir_source == "file" and not isinstance(module_str, str):
module_str = str(module_str)
Expand Down Expand Up @@ -393,7 +402,7 @@ def compile_to_vmfb(

flow_ir = flatbuffer_blob.decode("utf-8")

flow_ir_tk = replace_with_tk_kernels(flow_ir)
flow_ir_tk = replace_with_tk_kernels(flow_ir, batch_size)
module_str = "\n".join(flow_ir_tk)
flags.pop()
flags.extend(["--compile-from=flow"])
Expand Down
1 change: 1 addition & 0 deletions models/turbine_models/custom_models/sdxl_inference/unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class CompiledUnet(CompiledModule):
attn_spec=attn_spec,
flagset_keywords=["punet"] if use_punet else [],
add_tk_kernels=add_tk_kernels,
batch_size=batch_size,
)
if exit_on_vmfb:
exit()
Expand Down

0 comments on commit 71ffc84

Please sign in to comment.