download.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright 2020 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Annotated
  15. import typer
  16. def download(
  17. model_id: Annotated[str, typer.Argument(help="The model ID to download")],
  18. cache_dir: Annotated[str | None, typer.Option(help="Directory where to save files.")] = None,
  19. force_download: Annotated[
  20. bool, typer.Option(help="If set, the files will be downloaded even if they are already cached locally.")
  21. ] = False,
  22. trust_remote_code: Annotated[
  23. bool,
  24. typer.Option(
  25. help="Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you've reviewed the code as it will execute on your local machine"
  26. ),
  27. ] = False,
  28. ):
  29. """Download a model and its tokenizer from the Hub."""
  30. from ..models.auto import AutoModel, AutoTokenizer
  31. AutoModel.from_pretrained(
  32. model_id, cache_dir=cache_dir, force_download=force_download, trust_remote_code=trust_remote_code
  33. )
  34. AutoTokenizer.from_pretrained(
  35. model_id, cache_dir=cache_dir, force_download=force_download, trust_remote_code=trust_remote_code
  36. )