Created
August 17, 2018 22:30
-
-
Save arunmallya/7067466970e50c7effc89a65df4d42be to your computer and use it in GitHub Desktop.
Inplace normal_( ) bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.4.1\n" | |
] | |
} | |
], | |
"source": [ | |
"import torch\n", | |
"print(torch.__version__)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tensor([[0.2241, 0.1938, 0.6498, ..., 0.4053, 0.1032, 0.1593],\n", | |
" [0.7699, 0.2154, 0.2844, ..., 0.5927, 0.3669, 0.9740],\n", | |
" [0.4372, 0.6358, 0.5403, ..., 0.9147, 0.2274, 0.8001],\n", | |
" ...,\n", | |
" [0.9509, 0.0036, 0.3583, ..., 0.6677, 0.0050, 0.7659],\n", | |
" [0.9333, 0.6688, 0.4430, ..., 0.9379, 0.4267, 0.6492],\n", | |
" [0.0214, 0.9866, 0.3556, ..., 0.4019, 0.5550, 0.4936]])\n" | |
] | |
} | |
], | |
"source": [ | |
"a = torch.rand(5000, 4096)\n", | |
"b = a.clone()\n", | |
"c = a.clone()\n", | |
"d = a.clone()\n", | |
"print(a)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tensor([[ 0.1454, 1.9271, -0.2900, ..., -1.2863, 0.4496, -1.8988],\n", | |
" [ 0.7699, 0.2154, 0.2844, ..., 0.5927, 0.3669, 0.9740],\n", | |
" [ 0.4372, 0.6358, 0.5403, ..., 0.9147, 0.2274, 0.8001],\n", | |
" ...,\n", | |
" [ 0.9509, 0.0036, 0.3583, ..., 0.6677, 0.0050, 0.7659],\n", | |
" [ 0.9333, 0.6688, 0.4430, ..., 0.9379, 0.4267, 0.6492],\n", | |
" [ 0.0214, 0.9866, 0.3556, ..., 0.4019, 0.5550, 0.4936]])\n" | |
] | |
} | |
], | |
"source": [ | |
"a[4999:5000].normal_(0, 1)\n", | |
"print(a)\n", | |
"# Note that first row has changed." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tensor([[ 0.2241, 0.1938, 0.6498, ..., 0.4053, 0.1032, 0.1593],\n", | |
" [ 0.7699, 0.2154, 0.2844, ..., 0.5927, 0.3669, 0.9740],\n", | |
" [ 0.4372, 0.6358, 0.5403, ..., 0.9147, 0.2274, 0.8001],\n", | |
" ...,\n", | |
" [ 0.9509, 0.0036, 0.3583, ..., 0.6677, 0.0050, 0.7659],\n", | |
" [ 0.9333, 0.6688, 0.4430, ..., 0.9379, 0.4267, 0.6492],\n", | |
" [-1.0000, -1.0000, -1.0000, ..., -1.0000, -1.0000, -1.0000]])\n" | |
] | |
} | |
], | |
"source": [ | |
"b[4999:5000] = -1\n", | |
"print(b)\n", | |
"# Note that last row has changed." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tensor([[ 0.2241, 0.1938, 0.6498, ..., 0.4053, 0.1032, 0.1593],\n", | |
" [ 0.7699, 0.2154, 0.2844, ..., 0.5927, 0.3669, 0.9740],\n", | |
" [ 0.4372, 0.6358, 0.5403, ..., 0.9147, 0.2274, 0.8001],\n", | |
" ...,\n", | |
" [ 0.9509, 0.0036, 0.3583, ..., 0.6677, 0.0050, 0.7659],\n", | |
" [ 0.9333, 0.6688, 0.4430, ..., 0.9379, 0.4267, 0.6492],\n", | |
" [-1.0000, -1.0000, -1.0000, ..., -1.0000, -1.0000, -1.0000]])\n" | |
] | |
} | |
], | |
"source": [ | |
"c[4999:5000].copy_(torch.rand(1, 4096).fill_(-1))\n", | |
"print(c)\n", | |
"# Note that last row has changed." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tensor([[ 0.2241, 0.1938, 0.6498, ..., 0.4053, 0.1032, 0.1593],\n", | |
" [ 0.7699, 0.2154, 0.2844, ..., 0.5927, 0.3669, 0.9740],\n", | |
" [ 0.4372, 0.6358, 0.5403, ..., 0.9147, 0.2274, 0.8001],\n", | |
" ...,\n", | |
" [ 0.9509, 0.0036, 0.3583, ..., 0.6677, 0.0050, 0.7659],\n", | |
" [ 0.9333, 0.6688, 0.4430, ..., 0.9379, 0.4267, 0.6492],\n", | |
" [-1.0000, -1.0000, -1.0000, ..., -1.0000, -1.0000, -1.0000]])\n" | |
] | |
} | |
], | |
"source": [ | |
"d[4999:5000].fill_(-1)\n", | |
"print(d)\n", | |
"# Note that last row has changed." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment