Skip to content

Commit

Permalink
Use in-place multiplication and new_empty. (Atcold#756)
Browse files Browse the repository at this point in the history
To speed up computation use in-place tensor multiplication. Use new_empty to create a new tensor, eps, based off of tensor std's properties.
  • Loading branch information
szalmaf authored Jun 29, 2021
1 parent ab9eb59 commit dc26995
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 11-VAE.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
" def reparameterise(self, mu, logvar):\n",
" if self.training:\n",
" std = logvar.mul(0.5).exp_()\n",
" eps = std.data.new(std.size()).normal_()\n",
" return eps.mul(std).add_(mu)\n",
" eps = std.new_empty(std.size()).normal_()\n",
" return eps.mul_(std).add_(mu)\n",
" else:\n",
" return mu\n",
"\n",
Expand Down

0 comments on commit dc26995

Please sign in to comment.