Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] arguments of clip drop after fusion #97

Closed
soodoshll opened this issue Feb 12, 2023 · 1 comment · Fixed by #108
Closed

[Bug] arguments of clip drop after fusion #97

soodoshll opened this issue Feb 12, 2023 · 1 comment · Fixed by #108

Comments

@soodoshll
Copy link
Collaborator

This snippet gives the wrong result

import hidet
import numpy as np
import onnx

from onnx import numpy_helper, TensorProto
from onnx.helper import (
    make_model, make_node, make_graph,
    make_tensor_value_info)

X = make_tensor_value_info('X', TensorProto.FLOAT, [None, None])
Y = make_tensor_value_info('Y', TensorProto.FLOAT, [None, None])

v_min = numpy_helper.from_array(np.array(-1, dtype='float32'), name='v_min')
v_max = numpy_helper.from_array(np.array(1, dtype='float32'), name='v_max')

vmin = make_node('Constant', [], ['vmin'], value=v_min) 
vmax = make_node('Constant', [], ['vmax'], value=v_max) 

node = make_node('Clip',['X', 'vmin', 'vmax'], ['Y'])
graph = make_graph([vmin, vmax, node], 'foo', [X], [Y]) 
onnx_model = make_model(graph)

hidet.option.search_space(1)
hidet_onnx_module = hidet.graph.frontend.from_onnx(onnx_model)
hidet_onnx_module = hidet_onnx_module.to_cuda()

input_names = hidet_onnx_module.input_names

inputs = [hidet.asarray(np.array([6], dtype='float32'), device='cuda')]
symbol_data = [hidet.symbol_like(inputs[0])]
symbol_output = hidet_onnx_module(*symbol_data)
graph: hidet.FlowGraph = hidet.trace_from(symbol_output, inputs=symbol_data)
with hidet.graph.PassContext() as ctx:
    graph_opt: hidet.FlowGraph = hidet.graph.optimize(graph)
    print(graph_opt)
cuda_graph = graph_opt.cuda_graph()
outputs = cuda_graph.run(inputs)

print(outputs[0].detach().cpu().numpy())

It returns 6 instead of 1. The cuda code generated for clip op is just copying the input tensor without any condition statements. vmin and vmax seem to be dropped. Work well when fuse_operator_pass is disabled.

@yaoyaoding
Copy link
Member

Thanks @soodoshll.

KTong821 added a commit to KTong821/hidet that referenced this issue Apr 24, 2024
Define complete UNet, with forward pass broken into down, mid, and up
sections. Useful diagrams
[here](http://jalammar.github.io/illustrated-stable-diffusion/)

Uses blocks defined in hidet-org#97. Heavily reduced version from diffusers
containing only necessary features for stable diffusion v2-1.

Towards hidet-org#57.

---------

Co-authored-by: vadiklyutiy <[email protected]>
KTong821 added a commit to KTong821/hidet that referenced this issue Apr 24, 2024
Add UNet Down, Up, and Mid block definitions and attention transformer
utility layer.

Modules are designed so that kwargs passed to constructors are all the
same config from huggingface with minimal changes - lots of shared
values and too many parameters to list individually. Same kwargs are
passed to nested objects. Open to other suggestions, although this is a
single use case problem.

Towards hidet-org#57.
vadiklyutiy added a commit that referenced this issue Jul 22, 2024
Define complete UNet, with forward pass broken into down, mid, and up
sections. Useful diagrams
[here](http://jalammar.github.io/illustrated-stable-diffusion/)

Uses blocks defined in #97. Heavily reduced version from diffusers
containing only necessary features for stable diffusion v2-1.

Towards #57.

---------

Co-authored-by: vadiklyutiy <[email protected]>
vadiklyutiy pushed a commit that referenced this issue Jul 22, 2024
Add UNet Down, Up, and Mid block definitions and attention transformer
utility layer.

Modules are designed so that kwargs passed to constructors are all the
same config from huggingface with minimal changes - lots of shared
values and too many parameters to list individually. Same kwargs are
passed to nested objects. Open to other suggestions, although this is a
single use case problem.

Towards #57.
vadiklyutiy added a commit that referenced this issue Jul 23, 2024
Define complete UNet, with forward pass broken into down, mid, and up
sections. Useful diagrams
[here](http://jalammar.github.io/illustrated-stable-diffusion/)

Uses blocks defined in #97. Heavily reduced version from diffusers
containing only necessary features for stable diffusion v2-1.

Towards #57.

---------

Co-authored-by: vadiklyutiy <[email protected]>
vadiklyutiy pushed a commit that referenced this issue Jul 23, 2024
Add UNet Down, Up, and Mid block definitions and attention transformer
utility layer.

Modules are designed so that kwargs passed to constructors are all the
same config from huggingface with minimal changes - lots of shared
values and too many parameters to list individually. Same kwargs are
passed to nested objects. Open to other suggestions, although this is a
single use case problem.

Towards #57.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants