Skip to content

Commit

Permalink
Add inference mode to TAPIR and TAPIR pytorch colabs to save memory.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 670490071
Change-Id: I6eccc08899d008e09f1cc67d01100f40f1175bb3
  • Loading branch information
yangyi02 committed Sep 3, 2024
1 parent 495a013 commit a0cd34d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions colabs/torch_causal_tapir_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@
"model = model.eval()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "JH5jNtQAfTP4"
},
"outputs": [],
"source": [
"# @title Set to Inference Mode to Save Memory {form-width: \"25%\"}\n",
"\n",
"model = model.eval()\n",
"torch.set_grad_enabled(False)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -213,6 +227,8 @@
},
"outputs": [],
"source": [
"# @title Inference Functions {form-width: \"25%\"}\n",
"\n",
"def online_model_init(frames, query_points):\n",
" \"\"\"Initialize query features for the query points.\"\"\"\n",
" frames = preprocess_frames(frames)\n",
Expand Down
14 changes: 14 additions & 0 deletions colabs/torch_tapir_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@
"model = model.to(device)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5xN1TQIGfrDs"
},
"outputs": [],
"source": [
"# @title Set to Inference Mode to Save Memory {form-width: \"25%\"}\n",
"\n",
"model = model.eval()\n",
"torch.set_grad_enabled(False)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit a0cd34d

Please sign in to comment.