Skip to content

[Graph] Fix CompiledGraph aliasing bug#384

Merged
yaoyaoding merged 6 commits intohidet-org:mainfrom
Aalanli:fuzz_bugg
Dec 5, 2023
Merged

[Graph] Fix CompiledGraph aliasing bug#384
yaoyaoding merged 6 commits intohidet-org:mainfrom
Aalanli:fuzz_bugg

Conversation

@Aalanli
Copy link
Copy Markdown
Contributor

@Aalanli Aalanli commented Dec 2, 2023

Some graphs produce output tensors that alias. In the original case, the outputs of the aliasing tensors would be undefined (the result of empty). This PR fixes that by aliasing the outputs as well.

For example this script originally outputs garbage in the second tensor

import hidet

a = hidet.symbol([1, 2], device='cuda')
b = a.mean(1)
g = hidet.trace_from([b, b], a)

cg = g.build()
print(cg(hidet.ones([1, 2], device='cuda'))[1])

Copy link
Copy Markdown
Member

@yaoyaoding yaoyaoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Aalanli,

Thanks for the fix! There is an alternative way to fix this that you can consider. Besides, let's add the tests provided by the @Azyka to our test bed.

Comment on lines +211 to +214
if sig.alias is not None:
outputs.append(outputs[sig.alias])
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do the checking alternatively like

            if exec_idx in self.graph_execution.inputs_index:
                outputs.append(inputs[self.graph_execution.inputs_index.index(exec_idx)])
            elif exec_idx in self.graph_execution.weights_index:
                outputs.append(self.weights[self.graph_execution.weights_index.index(exec_idx)])
            elif exec_idx != self.graph_execution.outputs_index.index(exec_idx): # <--------
                outputs.append(outputs[self.graph_execution.outputs_index.index(exec_idx)])
            else:

so we do not need to modify the graph building process or an alias attribute.

How do you think @Aalanli ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested change doesn't work, but I see how to fix it.
Yeah, I think this way is better as well.

@yaoyaoding
Copy link
Copy Markdown
Member

Thanks @Aalanli !

@yaoyaoding
Copy link
Copy Markdown
Member

Could you also add the test to the repo?

@yaoyaoding
Copy link
Copy Markdown
Member

Thanks @Aalanli !

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 this pull request may close these issues.

2 participants