Skip to content

Commit

Permalink
Reveme import torch
Browse files Browse the repository at this point in the history
  • Loading branch information
xl0 committed Oct 15, 2023
1 parent bbb8cf9 commit 321a63f
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions nbs/02_functional.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,56 +165,12 @@
"outputs": [],
"source": [
"# | export\n",
"\n",
"\n",
"def dropout(x, p=0.5, training=True):\n",
" if p == 0:\n",
" return x\n",
"\n",
" return Dropout(x, p_drop=p, training=training).out"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"\n",
"a = torch.randn(2, 30, requires_grad=True)\n",
"\n",
"b = torch.nn.functional.dropout(a, p=0.1, training=True)\n",
"\n",
"b.sum().backward()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111,\n",
" 1.1111, 1.1111, 1.1111, 0.0000, 1.1111, 0.0000, 1.1111, 1.1111, 1.1111,\n",
" 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111,\n",
" 1.1111, 0.0000, 1.1111],\n",
" [1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 0.0000, 1.1111, 0.0000, 1.1111,\n",
" 0.0000, 1.1111, 0.0000, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111,\n",
" 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111, 1.1111,\n",
" 1.1111, 1.1111, 1.1111]])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.grad"
]
}
],
"metadata": {
Expand Down

0 comments on commit 321a63f

Please sign in to comment.