-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Feature] Add Ops of StyleGAN3 #2290
Conversation
It is recommended to place the kernels in |
}; | ||
template <> | ||
struct InternalType<c10::Half> { | ||
typedef float scalar_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected to used float as half?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. This is totally following https://github.com/NVlabs/stylegan3/blob/main/torch_utils/ops/bias_act.cu#L18
__device__ float g_fbuf[2 * MAX_FILTER_SIZE * | ||
MAX_FILTER_SIZE]; // Filters in global memory, | ||
// written by setup kernel. | ||
__device__ __constant__ float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant memory size is small, only 64kb. I am not sure if it is a good idea to use constant memory for this op.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is directly from https://github.com/NVlabs/stylegan3/blob/main/torch_utils/ops/filtered_lrelu.cu#L77. Maybe keeping it as origin is fine.
#include "pytorch_cpp_helper.hpp" | ||
#include "pytorch_device_registry.hpp" | ||
|
||
std::tuple<torch::Tensor, torch::Tensor, int> filtered_lrelu_op_impl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parrots only support return single tensor or return by args.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may not support parrots for now.
mmcv/ops/conv2d_gradfix.py
Outdated
weight_gradients_disabled = old | ||
|
||
|
||
def conv2d(input, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if we should put this in mmcv.ops. It seems like an advance conv2d with no custom ops. Any advice @zhouzaida ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He said it's ok.
Move ops out of MMEdit: open-mmlab/mmagic#1383 |
* add bias_act * support bias_act * support filtered_lrelu * support filtered_lrelu and upfirdn2d * support conv2d_gradfix and fix filtered_lrelu * fix lint * fix lint * fix c++ lint * fix part comments * fix lint * rm redundant header * fix upgrade pip * fix as comment * fix c++ lint * fix ci * fix-ut * fix as comments * add grad check * remove redundant template * Update mmcv/ops/bias_act.py Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com> * add typehint * fix as comment: * complete type hints * fix lint * add test for conv_gradfix * add test for conv_gradfix * fix lint * modify licenses and ops.md * add zh op md * add torch version policy for conv2d_gradfix * fix lint * fix as comments * rename impl * rm redudant function and add ut * fix as comment * fix lint * fix lint * fix as comments * fix lint * fix ut * fix as comment * fix as comment * fix as comment --------- Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
Transfer stylegan3' ops to MMCV.
Modification
Add following ops.
Sources:
https://github.com/NVlabs/stylegan3/tree/main/torch_utils/ops
Notes:
bias_act
may coverfused_bias_leakyrelu
.upfirdn2d
differs a lot from the one inMMCV
.BC-breaking (Optional)
bias_act
may coverfused_bias_leakyrelu
.upfirdn2d
differs a lot from the one inMMCV
.If we remove
fused_bias_leakyrelu
and updateupfirdn2d
, BC-breaking may appear.Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist
Before PR:
After PR: