MCPcopy
hub / github.com/bigcode-project/starcoder / _from_pretrained

Method _from_pretrained

chat/dialogues.py:114–172  ·  view source on GitHub ↗

Loads the dialogue template from a local directory or the Huggingface Hub. Args: model_id (`str`): ID of the model to load from the Huggingface Hub (e.g. `bigscience/bloom`). revision (`str`, *optional*): Revision of the model on the H

(
        cls: Type[T],
        *,
        model_id: str,
        revision: Optional[str],
        cache_dir: Optional[Union[str, Path]],
        force_download: bool,
        proxies: Optional[Dict],
        resume_download: bool,
        local_files_only: bool,
        token: Optional[Union[str, bool]],
        **model_kwargs,
    )

Source from the content-addressed store, hash-verified

112
113 @classmethod
114 def _from_pretrained(
115 cls: Type[T],
116 *,
117 model_id: str,
118 revision: Optional[str],
119 cache_dir: Optional[Union[str, Path]],
120 force_download: bool,
121 proxies: Optional[Dict],
122 resume_download: bool,
123 local_files_only: bool,
124 token: Optional[Union[str, bool]],
125 **model_kwargs,
126 ) -> T:
127 """Loads the dialogue template from a local directory or the Huggingface Hub.
128
129 Args:
130 model_id (`str`):
131 ID of the model to load from the Huggingface Hub (e.g. `bigscience/bloom`).
132 revision (`str`, *optional*):
133 Revision of the model on the Hub. Can be a branch name, a git tag or any commit id. Defaults to the
134 latest commit on `main` branch.
135 force_download (`bool`, *optional*, defaults to `False`):
136 Whether to force (re-)downloading the model weights and configuration files from the Hub, overriding
137 the existing cache.
138 resume_download (`bool`, *optional*, defaults to `False`):
139 Whether to delete incompletely received files. Will attempt to resume the download if such a file exists.
140 proxies (`Dict[str, str]`, *optional*):
141 A dictionary of proxy servers to use by protocol or endpoint (e.g., `{'http': 'foo.bar:3128',
142 'http://hostname': 'foo.bar:4012'}`).
143 token (`str` or `bool`, *optional*):
144 The token to use as HTTP bearer authorization for remote files. By default, it will use the token
145 cached when running `huggingface-cli login`.
146 cache_dir (`str`, `Path`, *optional*):
147 Path to the folder where cached files are stored.
148 local_files_only (`bool`, *optional*, defaults to `False`):
149 If `True`, avoid downloading the file and return the path to the local cached file if it exists.
150 model_kwargs:
151 Additional keyword arguments passed along to the [`~ModelHubMixin._from_pretrained`] method.
152 """
153 if os.path.isdir(model_id): # Can either be a local directory
154 print("Loading dialogue template from local directory")
155 template_file = os.path.join(model_id, TEMPLATE_FILENAME)
156 else: # Or a template on the Hub
157 template_file = hf_hub_download( # Download from the hub, passing same input args
158 repo_id=model_id,
159 filename=TEMPLATE_FILENAME,
160 revision=revision,
161 cache_dir=cache_dir,
162 force_download=force_download,
163 proxies=proxies,
164 resume_download=resume_download,
165 token=token,
166 local_files_only=local_files_only,
167 )
168
169 # Load template
170 with open(template_file, "r") as f:
171 data = json.load(f)

Callers

nothing calls this directly

Calls 1

from_dictMethod · 0.80

Tested by

no test coverage detected