MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / from_pretrained

Method from_pretrained

llama_cpp/llama.py:2316–2447  ·  view source on GitHub ↗

Create a Llama model from a pretrained model name or path. This method requires the huggingface-hub package. You can install it with `pip install huggingface-hub`. Args: repo_id: The model repo id. filename: A filename or glob pattern to match the mod

(
        cls,
        repo_id: str,
        filename: Optional[str],
        additional_files: Optional[List] = None,
        local_dir: Optional[Union[str, os.PathLike[str]]] = None,
        local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
        cache_dir: Optional[Union[str, os.PathLike[str]]] = None,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

2314
2315 @classmethod
2316 def from_pretrained(
2317 cls,
2318 repo_id: str,
2319 filename: Optional[str],
2320 additional_files: Optional[List] = None,
2321 local_dir: Optional[Union[str, os.PathLike[str]]] = None,
2322 local_dir_use_symlinks: Union[bool, Literal["auto"]] = "auto",
2323 cache_dir: Optional[Union[str, os.PathLike[str]]] = None,
2324 **kwargs: Any,
2325 ) -> "Llama":
2326 """Create a Llama model from a pretrained model name or path.
2327 This method requires the huggingface-hub package.
2328 You can install it with `pip install huggingface-hub`.
2329
2330 Args:
2331 repo_id: The model repo id.
2332 filename: A filename or glob pattern to match the model file in the repo.
2333 additional_files: A list of filenames or glob patterns to match additional model files in the repo.
2334 local_dir: The local directory to save the model to.
2335 local_dir_use_symlinks: Whether to use symlinks when downloading the model.
2336 **kwargs: Additional keyword arguments to pass to the Llama constructor.
2337
2338 Returns:
2339 A Llama model."""
2340 try:
2341 from huggingface_hub import hf_hub_download, HfFileSystem
2342 from huggingface_hub.utils import validate_repo_id
2343 except ImportError:
2344 raise ImportError(
2345 "Llama.from_pretrained requires the huggingface-hub package. "
2346 "You can install it with `pip install huggingface-hub`."
2347 )
2348
2349 validate_repo_id(repo_id)
2350
2351 hffs = HfFileSystem()
2352
2353 files = [
2354 file["name"] if isinstance(file, dict) else file
2355 for file in hffs.ls(repo_id, recursive=True)
2356 ]
2357
2358 # split each file into repo_id, subfolder, filename
2359 file_list: List[str] = []
2360 for file in files:
2361 rel_path = Path(file).relative_to(repo_id)
2362 file_list.append(str(rel_path))
2363
2364 # find the only/first shard file:
2365 matching_files = [file for file in file_list if fnmatch.fnmatch(file, filename)] # type: ignore
2366
2367 if len(matching_files) == 0:
2368 raise ValueError(
2369 f"No file found in {repo_id} that match {filename}\n\n"
2370 f"Available Files:\n{json.dumps(file_list)}"
2371 )
2372
2373 if len(matching_files) > 1:

Callers 3

main.pyFile · 0.45
local.pyFile · 0.45

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected