Skip to content

missing stuffs in torch.nn.utils #1243

Open

Description

@yueyinqiu
  • clip_grad_norm_
  • clip_grad_value_
  • convert_conv2d_weight_memory_format
  • fuse_conv_bn_eval
  • fuse_conv_bn_weights
  • fuse_linear_bn_eval
  • fuse_linear_bn_weights
  • parameters_to_vector
  • parametrizations
  • remove_spectral_norm
  • remove_weight_norm
  • rnn
  • skip_init
  • spectral_norm
  • stateless
  • vector_to_parameters

  • rnn is checked because the class do exist in TorchSharp, but actually not all the methods inside have been implemented.

Activity

  1. shaltielshmid commented on Feb 27, 2024

    @shaltielshmid
    Contributor

    Hi @yueyinqiu !
    Thanks for writing up the diff. I went through all the methods/modules that were missing in TorchSharp, and they are all pure PyTorch code that don't appear in LibTorch (the underlying C++ library). This means that we would need to rewrite all the methods ourselves in TorchSharp, which can take time to write properly.
    Do you have any specific methods that are more important for you in the short term? If so, I can dedicate some time to porting those over in the shorter term.

    All contributions are more than welcome, so if you want to port some of the functions as well, that would be great!

    [Side note: The clip_grad_norm function in PyTorch is deprecated and just calls the clip_grad_norm_ function, which exists in TorchSharp as well].

  2. yueyinqiu commented on Feb 28, 2024

    @yueyinqiu
    ContributorAuthor

    Hi @yueyinqiu ! Thanks for writing up the diff. I went through all the methods/modules that were missing in TorchSharp, and they are all pure PyTorch code that don't appear in LibTorch (the underlying C++ library). This means that we would need to rewrite all the methods ourselves in TorchSharp, which can take time to write properly. Do you have any specific methods that are more important for you in the short term? If so, I can dedicate some time to porting those over in the shorter term.

    All contributions are more than welcome, so if you want to port some of the functions as well, that would be great!

    [Side note: The clip_grad_norm function in PyTorch is deprecated and just calls the clip_grad_norm_ function, which exists in TorchSharp as well].

    Well in fact I'm just a newbie to deep learning and I was trying reproducing some others' work which used spectral_norm. But I have later found that they skipped all the spectral_norms in their final configuration. So it's not that urgent and I'm just making a note here.

    Actually I'd like to contribute the project. It's so great to be able to use C# instead of Python. However I'm afraid that my unfamiliarity with deep learning and PyTorch will mess everything up :(

    (Please feel free to edit my list, like just remove the clip_grad_norm here if you think it's appropriate.)

  3. yueyinqiu commented on Mar 7, 2024

    @yueyinqiu
    ContributorAuthor

    Hi @yueyinqiu ! Thanks for writing up the diff. I went through all the methods/modules that were missing in TorchSharp, and they are all pure PyTorch code that don't appear in LibTorch (the underlying C++ library). This means that we would need to rewrite all the methods ourselves in TorchSharp, which can take time to write properly. Do you have any specific methods that are more important for you in the short term? If so, I can dedicate some time to porting those over in the shorter term.

    All contributions are more than welcome, so if you want to port some of the functions as well, that would be great!

    [Side note: The clip_grad_norm function in PyTorch is deprecated and just calls the clip_grad_norm_ function, which exists in TorchSharp as well].

    I've tried to add fuse_conv_bn_weights and fuse_linear_bn_weights in #1262 . Could you please take a look and give me some advice?

  4. NiklasGustafsson commented on Mar 15, 2024

    @NiklasGustafsson

    @yueyinqiu -- I just merged your PR. Please edit the to-do list in the first comment to reflect your changes.

  5. yueyinqiu commented on Mar 16, 2024

    @yueyinqiu
    ContributorAuthor

    @yueyinqiu -- I just merged your PR. Please edit the to-do list in the first comment to reflect your changes.

    yes and thanks a lot

  6. NiklasGustafsson commented on Jun 19, 2024

    @NiklasGustafsson

    @yueyinqiu -- I was taking a look at this again -- the fuse_***_eval methods, how commonly used are those? They seem straight-forward enough, but how important are they to have?

  7. yueyinqiu commented on Jun 20, 2024

    @yueyinqiu
    ContributorAuthor

    Hmm... I'm not sure. I'm not really familiar with deep learning. But implementing this won't cost a lot, I think?

    Are you considering this because of #1259, and hesitating whether to have generalized types for Convs and BatchNorms? I think those types would be great, but it's really hard to design them well, and it won't bother too much to use overloads if we don't have such general types.

  8. NiklasGustafsson commented on Jun 20, 2024

    @NiklasGustafsson

    fuse_linear_bn_eval and fuse_conv_bn_eval will be easier to implement once we have the restructured module implementations merged, so I'll hold off until then.

  9. yueyinqiu commented on Jun 20, 2024

    @yueyinqiu
    ContributorAuthor

    I think that would be a good idea.

  10. alinpahontu2912 commented on Feb 16, 2026

    @alinpahontu2912
    Member

    Hi @yueyinqiu!

    Thank you for bringing up the missing functionalities in torch.nn.utils, and for your contributions to the discussion over the past couple of years. It looks like some methods are still pending, particularly convert_conv2d_weight_memory_format, fuse_conv_bn_eval, and others.

    Since TorchSharp has evolved significantly since this issue was opened, I wanted to check in and see if this issue is still relevant or if it has been resolved in the meantime. If you have any updated information or insights, please let us know!

    Thanks again for your involvement, and we appreciate your patience!

  11. yueyinqiu commented on Feb 17, 2026

    @yueyinqiu
    ContributorAuthor

    As far as I know, these functions haven't been implemented yet. I recall that we were in the middle of a major refactor #1259 at the time, which would expose more properties at the C# layer. Since those properties are essential for implementing these functions, we decided to wait for that refactor to be completed.

    #1259 is actually a foundational change that impacts many other areas of the project, though I can't recall for certain if it was ever fully merged or finished. It might be worth checking the status of #1259 first. (That specific PR was closed—possibly to avoid taxing the CI/CD at the time.) The spreadsheet in #1271 (comment) may also help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions