Skip to content

torch.nn.functional.l1_loss computes a criterion with the MSE, not the MAE #1359

Closed

Description

@RensOliemans

The L1Loss should create a criterion that measures the MAE error, but in TorchSharp it measures the MSE.

I believe that this is incorrect. See the following screenshot comparing TorchSharp and pytorch, which I believe should get identical results, but don't:
image

See the call to functional::mse_loss:

Tensor THSNN_l1_loss(const Tensor input, const Tensor target, const int64_t reduction)
{
CATCH_RETURN_Tensor(
auto opts = torch::nn::functional::MSELossFuncOptions();
ApplyReduction(opts, reduction);
res = ResultTensor(torch::nn::functional::mse_loss(*input, *target, opts));
)
}

If this is indeed incorrect, I would be happy to submit a fix in a PR, but am still figuring out how to make my projects use the locally built version of TorchSharp—I'm not the biggest C# / dotnet / nuget expert.

Activity

  1. NiklasGustafsson commented on Jul 18, 2024

    @NiklasGustafsson

    Thank you for the report.

    You are correct, the C++ implementation calls the wrong libtorch function -- mse_loss() instead of l1_loss().

    I can fix it, or you can submit a PR and get yourself on our 'Contributor' board... :-)

  2. added a commit that references this issue on Jul 18, 2024
  3. NiklasGustafsson commented on Jul 19, 2024

    @NiklasGustafsson

    @RensOliemans -- take a look at #1360

  4. added a commit that references this issue on Jul 19, 2024
    1f7e50b
  5. RensOliemans commented on Jul 19, 2024

    @RensOliemans
    Author

    Thanks, I had the same diff in RensOliemans@1f7e50b but didn't push it yet: I haven't figured out how to build the TorchSharp so that I get a .nupkg that I can test locally. Is that possible on Linux?

  6. NiklasGustafsson commented on Jul 19, 2024

    @NiklasGustafsson

    Does dotnet pack not work?

  7. NiklasGustafsson commented on Jul 19, 2024

    @NiklasGustafsson

    You can look in the azure_pipeline.yaml file for the exact CLI arguments to provide to dotnet pack

  8. linked a pull request that will close this issueAddress issue #1359 #1360on Jul 19, 2024
  9. added a commit that references this issue on Jul 19, 2024
  10. RensOliemans commented on Jul 19, 2024

    @RensOliemans
    Author
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