Skip to content

Commit

Permalink
Move .cache/torch/hub to local for openvoice (#2359)
Browse files Browse the repository at this point in the history
CVS-149572
  • Loading branch information
sbalandi authored Sep 4, 2024
1 parent 0a1d9b9 commit 40d8b01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions .ci/validate_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def get_pip_openvino_version(text_input: str) -> str:
def run_test(notebook_path: Path, root, timeout=7200, keep_artifacts=False, report_dir=".") -> Optional[Tuple[str, int, float, str, str]]:
os.environ["HUGGINGFACE_HUB_CACHE"] = str(notebook_path.parent)
os.environ["HF_HUB_CACHE"] = str(notebook_path.parent)
os.environ["TORCH_HOME"] = str(notebook_path.parent)
print(f"RUN {notebook_path.relative_to(root)}", flush=True)
result = None

Expand Down
30 changes: 22 additions & 8 deletions notebooks/openvoice/openvoice.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@
"Audio(ref_speaker_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"torch_hub_local = Path(\"torch_hub_local/\")\n",
"%env TORCH_HOME={str(torch_hub_local.absolute())}"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand All @@ -768,17 +778,21 @@
"\n",
"url = \"https://github.com/snakers4/silero-vad/zipball/v3.0\"\n",
"\n",
"torch_hub_dir = torch.hub.get_dir()\n",
"torch_hub_dir = torch_hub_local / \"hub\"\n",
"torch.hub.set_dir(torch_hub_dir.as_posix())\n",
"\n",
"zip_filename = \"v3.0.zip\"\n",
"download_file(url, directory=torch_hub_dir, filename=zip_filename)\n",
"zip_ref = zipfile.ZipFile(Path(torch_hub_dir, zip_filename).as_posix(), \"r\")\n",
"output_path = Path(torch_hub_dir, \"v3.0\")\n",
"zip_ref.extractall(path=output_path.as_posix())\n",
"zip_ref.close()\n",
"output_path = torch_hub_dir / \"v3.0\"\n",
"if not (torch_hub_dir / zip_filename).exists():\n",
" download_file(url, directory=torch_hub_dir, filename=zip_filename)\n",
" zip_ref = zipfile.ZipFile((torch_hub_dir / zip_filename).as_posix(), \"r\")\n",
" zip_ref.extractall(path=output_path.as_posix())\n",
" zip_ref.close()\n",
"\n",
"v3_dirs = [d for d in output_path.iterdir() if \"snakers4-silero-vad\" in d.as_posix()]\n",
"if len(v3_dirs) > 0:\n",
" os.symlink(v3_dirs[0].as_posix(), Path(torch_hub_dir, \"snakers4_silero-vad_v3.0\").as_posix())"
"if len(v3_dirs) > 0 and not (torch_hub_dir / \"snakers4_silero-vad_v3.0\").exists():\n",
" v3_dir = str(v3_dirs[0])\n",
" os.rename(str(v3_dirs[0]), (torch_hub_dir / \"snakers4_silero-vad_v3.0\").as_posix())"
]
},
{
Expand Down

0 comments on commit 40d8b01

Please sign in to comment.