dotnet / TorchSharp

A .NET library that provides access to the library that powers PyTorch.
MIT License
1.4k stars 182 forks source link

Make API more easy to use by following python's syntax. #76

Closed Oceania2018 closed 4 years ago

Oceania2018 commented 5 years ago

Is it possible change the high level API like what SciSharp's done? Check the README: https://github.com/SciSharp/TensorFlow.NET.

For example:

using TorchSharp;

var x = new FloatTensor (100);   // 1D-tensor with 100 elements

Will be

using torch = TorchSharp.Torch;

var x = torch.tensor(100)   // 1D-tensor with 100 elements

Mirror API first would make progress be faster that move ML model to .NET world. Project will be done faster than ML.NET. @migueldeicaza When most of the thing runs well, we can refactor code that be more .NET conventions.

interesaaat commented 5 years ago

I personally believe that we should stay closer to C# conventions instead of exactly mirroring the python API. The goal of the project is in fact to provide a way for C# users to run and build deep learning models through PyTorch, and not the other way around (i.e., PyTorch users that want to use C# instead of python). For instance I have several problems with this:

Oceania2018 commented 5 years ago

We could reactive the KerasSharp, wrap the TorchSharp and TensorFlow.NET or TensorFlowSharp, ML.NET and CNTK.

interesaaat commented 5 years ago

This could be a good option! I also like the idea of using Keras API on top of ML.NET (how does that work?)

Oceania2018 commented 5 years ago

@interesaaat The author of KerasSharp doesn't response https://github.com/cesarsouza/keras-sharp/issues/29 .

deepakkumar1984 commented 5 years ago

A similar project like keras sharp with multiple backends. I can try to include torchsharp soon. https://github.com/deepakkumar1984/SiaNet/

Oceania2018 commented 5 years ago

@deepakkumar1984 Could you add TensorFlow.NET as a backend?

deepakkumar1984 commented 5 years ago

I can add it as a variation to Tensorflow implementation. Already using Tensorflowsharp but I can this library as well and rest upto the user to use specific backend.

On Tue, Mar 26, 2019 at 2:56 PM Haiping notifications@github.com wrote:

@deepakkumar1984 https://github.com/deepakkumar1984 Could you add TensorFlow.NET https://github.com/SciSharp/TensorFlow.NET as a backend?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xamarin/TorchSharp/issues/76#issuecomment-476470767, or mute the thread https://github.com/notifications/unsubscribe-auth/AGCQKWd2wicdH69-UfaI1F6_U5x5jXDnks5vaaGAgaJpZM4bXXcp .

-- Regards, Deepak

Oceania2018 commented 5 years ago

Refer this thread, you will know how valuable it is. The most important is TensorFlow.NET can Build Graph -> Train -> Inference model in one library. @deepakkumar1984

deepakkumar1984 commented 5 years ago

Does it support CUDA?

On Tue, Mar 26, 2019 at 3:15 PM Haiping notifications@github.com wrote:

Refer this thread https://github.com/SciSharp/TensorFlow.NET/issues/180, you will know how valuable it is. The most important is TensorFlow.NET can Build Graph -> Train -> Inference model in one library. @deepakkumar1984 https://github.com/deepakkumar1984

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xamarin/TorchSharp/issues/76#issuecomment-476473746, or mute the thread https://github.com/notifications/unsubscribe-auth/AGCQKdAIepDjgSm7xPYCzufD2jZ-8EmJks5vaaXRgaJpZM4bXXcp .

-- Regards, Deepak

Oceania2018 commented 5 years ago

Sure, cross-platform, run in CUDA.

JeroMiya commented 5 years ago

This seems to be a recurring issue with libraries ported from other languages to .NET - what naming convention to use for the API?

There are two schools of thought:

  1. Keep close to the original library's naming conventions, even if they conflict with the .NET naming conventions, to make it easier to port code from samples and documentation into the new .NET library.
  2. Use the .NET naming conventions, making the library easier to use for .NET developers. These naming conventions convey information (e.g. property vs function vs field etc...) and when they are not followed code can become more difficult to read.

Both of these schools of thought are equally valid, but of course they conflict with each other. I think school of thought 1 is best for the early stages of the library, getting started, etc... but I think long term 2 is the best. Supporting both in parallel would be ideal though. It would be nice if there were some automated way to generate a .NET convention version of the API surface in parallel to the Python-style API.

As an aside, it's interesting to me that F# uses a naming convention more like Python (for historical reasons, given F# is based on the ML family of languages), but only for private methods within an implementation and for the F# standard library. Even for F# facing libraries written in F#, the recommended conventions for public facing APIs is to use the .NET convention, though that seems to be inconsistently followed in the wild.

dsyme commented 4 years ago

Just to note that if I was starting this repo from scratch, I would make it part of SciSharp, and follow SciSharp's naming conventions (i.e. use PyTorch Python naming conventions)

But for now we will stick to the naming conventions we have here

dsyme commented 4 years ago

I'm closing this as it's covered by #95