tenstorrent / tt-forge-fe

The TT-Forge FE is a graph compiler designed to optimize and transform computational graphs for deep learning models, enhancing their performance and efficiency.
https://docs.tenstorrent.com/tt-forge-fe/
Apache License 2.0
20 stars 3 forks source link

Decompose AvgPool3d Op to Conv3d for Support #714

Closed kamalrajkannan78 closed 14 hours ago

kamalrajkannan78 commented 1 week ago

Summary:

weight_value = 1.0 / (kD * kH * kW)
weight = torch.ones(1, 1, kD, kH, kW) * weight_value

Logs

dgolubovicTT commented 1 week ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn.

What is your take in this case @nvukobratTT

nvukobratTT commented 1 week ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn.

What is your take in this case @nvukobratTT

Few notes before more detailed CR:

  1. I'm okay with doing these decompositions as TTNN lacks support for these ops. Mostly because it's questionable when (if) they are going to add those. That said, @kamalrajkannan78 can you open two issues on tt-metal repo with a op support request and like them here? Ideally, we should like to have those ops on TTNN as well.
  2. Can we decompose avg pool 3d using avg pool 2d? Current solution looks mathematically correct, however, it will impose confusions when when someone starts to debug what is happening here. From my side, it seems cleaner to decompose conv3d using conv2d, and doing similar for avg pool 3d using avg pool 2d. What are your thoughts guys?
  3. For avg pool 3d we can use a similar decomposition approach:
    • Apply avg pool 2d over on each depth slice (keep intermediate results for each slice)
    • Stack those results along depth dim
    • Average those results across depth dim
kamalrajkannan78 commented 1 week ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn.

What is your take in this case @nvukobratTT

thanks for the review @dgolubovicTT , @nvukobratTT

kamalrajkannan78 commented 1 week ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn. What is your take in this case @nvukobratTT

Few notes before more detailed CR:

  1. I'm okay with doing these decompositions as TTNN lacks support for these ops. Mostly because it's questionable when (if) they are going to add those. That said, @kamalrajkannan78 can you open two issues on tt-metal repo with a op support request and like them here? Ideally, we should like to have those ops on TTNN as well.
  2. Can we decompose avg pool 3d using avg pool 2d? Current solution looks mathematically correct, however, it will impose confusions when when someone starts to debug what is happening here. From my side, it seems cleaner to decompose conv3d using conv2d, and doing similar for avg pool 3d using avg pool 2d. What are your thoughts guys?
  3. For avg pool 3d we can use a similar decomposition approach:

    • Apply avg pool 2d over on each depth slice (keep intermediate results for each slice)
    • Stack those results along depth dim
    • Average those results across depth dim

sure @nvukobratTT I will try to decompose avgpool3d in a suggested way!

dgolubovicTT commented 1 week ago

Decomposing avgpool3d to avgpool2d like @nvukobratTT layed out sounds great. Let's do it like that!

kamalrajkannan78 commented 1 week ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn. What is your take in this case @nvukobratTT

Few notes before more detailed CR:

  1. I'm okay with doing these decompositions as TTNN lacks support for these ops. Mostly because it's questionable when (if) they are going to add those. That said, @kamalrajkannan78 can you open two issues on tt-metal repo with a op support request and like them here? Ideally, we should like to have those ops on TTNN as well.
  2. Can we decompose avg pool 3d using avg pool 2d? Current solution looks mathematically correct, however, it will impose confusions when when someone starts to debug what is happening here. From my side, it seems cleaner to decompose conv3d using conv2d, and doing similar for avg pool 3d using avg pool 2d. What are your thoughts guys?
  3. For avg pool 3d we can use a similar decomposition approach:

    • Apply avg pool 2d over on each depth slice (keep intermediate results for each slice)
    • Stack those results along depth dim
    • Average those results across depth dim
nvukobratTT commented 4 days ago

Thanks for the issues @kamalrajkannan78 !

FYI, I updated labels nad added project information to reflect more precisely what our request is :))

kamalrajkannan78 commented 3 days ago

Thanks for the issues @kamalrajkannan78 !

FYI, I updated labels nad added project information to reflect more precisely what our request is :))

Thanks for adding those details @nvukobratTT

kamalrajkannan78 commented 14 hours ago

@kamalrajkannan78 @nvukobratTT Can you share why we decompose avgpool3d? Since tt-metal has avgpool2d, can we expect it to have avgpool3d support, or ask for it? Do we know if they had the need for avgpool3d themselves? This decomposition is logical but whenever I see some decomposition lately, I start thinking about how performant decomposed subgraph is compared to native op in ttnn. So if we do decompose, we are less overfitting to ttnn, and if we don't do it and require ttnn support to lower directly, we are maybe overfitting to ttnn. What is your take in this case @nvukobratTT

Few notes before more detailed CR:

  1. I'm okay with doing these decompositions as TTNN lacks support for these ops. Mostly because it's questionable when (if) they are going to add those. That said, @kamalrajkannan78 can you open two issues on tt-metal repo with a op support request and like them here? Ideally, we should like to have those ops on TTNN as well.
  2. Can we decompose avg pool 3d using avg pool 2d? Current solution looks mathematically correct, however, it will impose confusions when when someone starts to debug what is happening here. From my side, it seems cleaner to decompose conv3d using conv2d, and doing similar for avg pool 3d using avg pool 2d. What are your thoughts guys?
  3. For avg pool 3d we can use a similar decomposition approach:

    • Apply avg pool 2d over on each depth slice (keep intermediate results for each slice)
    • Stack those results along depth dim
    • Average those results across depth dim

https://github.com/tenstorrent/tt-forge-fe/pull/741