Skip to content

Conversation

@goldsborough
Copy link
Contributor

An end-to-end tutorial for the C++ frontend.

@soumith @ezyang maybe want to give it a quick glance?

@goldsborough goldsborough changed the title Wrote C++ frontend tutorial C++ frontend Tutorial Jan 9, 2019
@netlify
Copy link

netlify bot commented Jan 9, 2019

Deploy preview for pytorch-tutorials-preview ready!

Built with commit 0e665a6

https://deploy-preview-408--pytorch-tutorials-preview.netlify.com

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

b = register_parameter("b", torch::randn(M));
}
torch::Tensor forward(torch::Tensor input) {
return torch::admm(b, input, W);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: torch::addmm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

<https://arxiv.org/abs/1511.06434>`_ -- one of the first and simplest of its
kind, but entirely sufficient for this task.

What was a GAN aGAN?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a typo or an intentional pun?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a pun :)

@brianjo
Copy link
Contributor

brianjo commented Jan 10, 2019

Here's a direct link to the preview for easier reading. https://deploy-preview-408--pytorch-tutorials-preview.netlify.com/advanced/cpp_frontend.html

@ezyang
Copy link
Contributor

ezyang commented Jan 14, 2019

It looks reasonable. Do you want editing or to ship as is?

@soumith
Copy link
Contributor

soumith commented Jan 14, 2019

looks pretty good and well-structured to me. thanks a lot Peter! :)

another_bias = register_parameter("b", torch::randn(M));
}
torch::Tensor forward(torch::Tensor input) {
return linear(input) + another_bias;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A compile error occurred at this line when building with vs2017. The error disappeared after I changed linear(input) to linear->forward(input)

Copy link

@CDitzel CDitzel Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be an issue here regarding the general syntax of the forward pass.

I suppose an overload of the call operator was intended here but as of now is not supported by neither the stable version nor the nightly build of libtorch. I find the overload highly desirable as it lends itself towards the python API and seems way more natural than having to call a forward function.

Copy link
Contributor Author

@goldsborough goldsborough Jan 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate everyone trying out the examples, but there are some PRs that I am landing before this code works, which is why this tutorial is not yet published. The call operator is coming with pytorch/pytorch#15831 which I'll land right now, and then the example repository, and then this PR

Copy link
Contributor

@apaszke apaszke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, but I have one question

torch::load(generator_optimizer, "generator-optimizer-checkpoint.pt");
torch::load(discriminator, "discriminator-checkpoint.pt");
torch::load(
discriminator_optimizer, "discriminator-optimizer-checkpoint.pt");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: how does C++ API deal with optimizers holding references to module parameters in this case? In Python one has to be careful to pickle the optimizer together with a module to keep the sharing intact, but in here you're not doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tensor deserialization is in-place in the C++ serialization API, so the tensors to which the optimizers hold references should stay valid (as I see it)

@soumith soumith merged commit d697369 into pytorch:master Jan 15, 2019
rodrigo-techera pushed a commit to Experience-Monks/tutorials that referenced this pull request Nov 29, 2021
* Wrote C++ frontend tutorial

* Adding image and index entry

* Update links to examples repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants