bigdl-core-cpp 2.5.0b20240729__py3-none-manylinux2010_x86_64.whl → 2.5.0b20240731__py3-none-manylinux2010_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,503 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+ import json
5
+ import yaml
6
+ import logging
7
+ from pathlib import Path
8
+ from typing import Any, Literal, Optional
9
+ from dataclasses import dataclass
10
+
11
+ from .constants import Keys
12
+
13
+ import gguf
14
+
15
+ logger = logging.getLogger("metadata")
16
+
17
+
18
+ @dataclass
19
+ class Metadata:
20
+ # Authorship Metadata to be written to GGUF KV Store
21
+ name: Optional[str] = None
22
+ author: Optional[str] = None
23
+ version: Optional[str] = None
24
+ organization: Optional[str] = None
25
+ finetune: Optional[str] = None
26
+ basename: Optional[str] = None
27
+ description: Optional[str] = None
28
+ quantized_by: Optional[str] = None
29
+ size_label: Optional[str] = None
30
+ url: Optional[str] = None
31
+ doi: Optional[str] = None
32
+ uuid: Optional[str] = None
33
+ repo_url: Optional[str] = None
34
+ source_url: Optional[str] = None
35
+ source_doi: Optional[str] = None
36
+ source_uuid: Optional[str] = None
37
+ source_repo_url: Optional[str] = None
38
+ license: Optional[str] = None
39
+ license_name: Optional[str] = None
40
+ license_link: Optional[str] = None
41
+ base_models: Optional[list[dict]] = None
42
+ tags: Optional[list[str]] = None
43
+ languages: Optional[list[str]] = None
44
+ datasets: Optional[list[str]] = None
45
+
46
+ @staticmethod
47
+ def load(metadata_override_path: Optional[Path] = None, model_path: Optional[Path] = None, model_name: Optional[str] = None, total_params: int = 0) -> Metadata:
48
+ # This grabs as many contextual authorship metadata as possible from the model repository
49
+ # making any conversion as required to match the gguf kv store metadata format
50
+ # as well as giving users the ability to override any authorship metadata that may be incorrect
51
+
52
+ # Create a new Metadata instance
53
+ metadata = Metadata()
54
+
55
+ model_card = Metadata.load_model_card(model_path)
56
+ hf_params = Metadata.load_hf_parameters(model_path)
57
+ # TODO: load adapter_config.json when possible, it usually contains the base model of the LoRA adapter
58
+
59
+ # heuristics
60
+ metadata = Metadata.apply_metadata_heuristic(metadata, model_card, hf_params, model_path, total_params)
61
+
62
+ # Metadata Override File Provided
63
+ # This is based on LLM_KV_NAMES mapping in llama.cpp
64
+ metadata_override = Metadata.load_metadata_override(metadata_override_path)
65
+
66
+ metadata.name = metadata_override.get(Keys.General.NAME, metadata.name)
67
+ metadata.author = metadata_override.get(Keys.General.AUTHOR, metadata.author)
68
+ metadata.version = metadata_override.get(Keys.General.VERSION, metadata.version)
69
+ metadata.organization = metadata_override.get(Keys.General.ORGANIZATION, metadata.organization)
70
+
71
+ metadata.finetune = metadata_override.get(Keys.General.FINETUNE, metadata.finetune)
72
+ metadata.basename = metadata_override.get(Keys.General.BASENAME, metadata.basename)
73
+
74
+ metadata.description = metadata_override.get(Keys.General.DESCRIPTION, metadata.description)
75
+ metadata.quantized_by = metadata_override.get(Keys.General.QUANTIZED_BY, metadata.quantized_by)
76
+
77
+ metadata.size_label = metadata_override.get(Keys.General.SIZE_LABEL, metadata.size_label)
78
+ metadata.license_name = metadata_override.get(Keys.General.LICENSE_NAME, metadata.license_name)
79
+ metadata.license_link = metadata_override.get(Keys.General.LICENSE_LINK, metadata.license_link)
80
+
81
+ metadata.url = metadata_override.get(Keys.General.URL, metadata.url)
82
+ metadata.doi = metadata_override.get(Keys.General.DOI, metadata.doi)
83
+ metadata.uuid = metadata_override.get(Keys.General.UUID, metadata.uuid)
84
+ metadata.repo_url = metadata_override.get(Keys.General.REPO_URL, metadata.repo_url)
85
+
86
+ metadata.source_url = metadata_override.get(Keys.General.SOURCE_URL, metadata.source_url)
87
+ metadata.source_doi = metadata_override.get(Keys.General.SOURCE_DOI, metadata.source_doi)
88
+ metadata.source_uuid = metadata_override.get(Keys.General.SOURCE_UUID, metadata.source_uuid)
89
+ metadata.source_repo_url = metadata_override.get(Keys.General.SOURCE_REPO_URL, metadata.source_repo_url)
90
+
91
+ # Base Models is received here as an array of models
92
+ metadata.base_models = metadata_override.get("general.base_models", metadata.base_models)
93
+
94
+ metadata.tags = metadata_override.get(Keys.General.TAGS, metadata.tags)
95
+ metadata.languages = metadata_override.get(Keys.General.LANGUAGES, metadata.languages)
96
+ metadata.datasets = metadata_override.get(Keys.General.DATASETS, metadata.datasets)
97
+
98
+ # Direct Metadata Override (via direct cli argument)
99
+ if model_name is not None:
100
+ metadata.name = model_name
101
+
102
+ return metadata
103
+
104
+ @staticmethod
105
+ def load_metadata_override(metadata_override_path: Optional[Path] = None) -> dict[str, Any]:
106
+ if metadata_override_path is None or not metadata_override_path.is_file():
107
+ return {}
108
+
109
+ with open(metadata_override_path, "r", encoding="utf-8") as f:
110
+ return json.load(f)
111
+
112
+ @staticmethod
113
+ def load_model_card(model_path: Optional[Path] = None) -> dict[str, Any]:
114
+ if model_path is None or not model_path.is_dir():
115
+ return {}
116
+
117
+ model_card_path = model_path / "README.md"
118
+
119
+ if not model_card_path.is_file():
120
+ return {}
121
+
122
+ # The model card metadata is assumed to always be in YAML
123
+ # ref: https://github.com/huggingface/transformers/blob/a5c642fe7a1f25d3bdcd76991443ba6ff7ee34b2/src/transformers/modelcard.py#L468-L473
124
+ with open(model_card_path, "r", encoding="utf-8") as f:
125
+ if f.readline() == "---\n":
126
+ raw = f.read().partition("---\n")[0]
127
+ data = yaml.safe_load(raw)
128
+ if isinstance(data, dict):
129
+ return data
130
+ else:
131
+ logger.error(f"while reading YAML model card frontmatter, data is {type(data)} instead of dict")
132
+ return {}
133
+ else:
134
+ return {}
135
+
136
+ @staticmethod
137
+ def load_hf_parameters(model_path: Optional[Path] = None) -> dict[str, Any]:
138
+ if model_path is None or not model_path.is_dir():
139
+ return {}
140
+
141
+ config_path = model_path / "config.json"
142
+
143
+ if not config_path.is_file():
144
+ return {}
145
+
146
+ with open(config_path, "r", encoding="utf-8") as f:
147
+ return json.load(f)
148
+
149
+ @staticmethod
150
+ def id_to_title(string):
151
+ # Convert capitalization into title form unless acronym or version number
152
+ return ' '.join([w.title() if w.islower() and not re.match(r'^(v\d+(?:\.\d+)*|\d.*)$', w) else w for w in string.strip().replace('-', ' ').split()])
153
+
154
+ @staticmethod
155
+ def get_model_id_components(model_id: Optional[str] = None, total_params: int = 0) -> tuple[str | None, str | None, str | None, str | None, str | None, str | None]:
156
+ # Huggingface often store model id as '<org>/<model name>'
157
+ # so let's parse it and apply some heuristics if possible for model name components
158
+
159
+ if model_id is None:
160
+ # model ID missing
161
+ return None, None, None, None, None, None
162
+
163
+ if ' ' in model_id:
164
+ # model ID is actually a normal human sentence
165
+ # which means its most likely a normal model name only
166
+ # not part of the hugging face naming standard, but whatever
167
+ return model_id, None, None, None, None, None
168
+
169
+ if '/' in model_id:
170
+ # model ID (huggingface style)
171
+ org_component, model_full_name_component = model_id.split('/', 1)
172
+ else:
173
+ # model ID but missing org components
174
+ org_component, model_full_name_component = None, model_id
175
+
176
+ # Check if we erroneously matched against './' or '../' etc...
177
+ if org_component is not None and org_component[0] == '.':
178
+ org_component = None
179
+
180
+ name_parts: list[str] = model_full_name_component.split('-')
181
+
182
+ # Remove empty parts
183
+ for i in reversed(range(len(name_parts))):
184
+ if len(name_parts[i]) == 0:
185
+ del name_parts[i]
186
+
187
+ name_types: list[
188
+ set[Literal["basename", "size_label", "finetune", "version", "type"]]
189
+ ] = [set() for _ in name_parts]
190
+
191
+ # Annotate the name
192
+ for i, part in enumerate(name_parts):
193
+ # Version
194
+ if re.fullmatch(r'(v|iter)?\d+([.]\d+)*', part, re.IGNORECASE):
195
+ name_types[i].add("version")
196
+ # Quant type (should not be there for base models, but still annotated)
197
+ elif re.fullmatch(r'i?q\d(_\w)*|b?fp?(16|32)', part, re.IGNORECASE):
198
+ name_types[i].add("type")
199
+ name_parts[i] = part.upper()
200
+ # Model size
201
+ elif i > 0 and re.fullmatch(r'(([A]|\d+[x])?\d+([._]\d+)?[KMBT][\d]?|small|mini|medium|large|x?xl)', part, re.IGNORECASE):
202
+ part = part.replace("_", ".")
203
+ # Handle weird bloom-7b1 notation
204
+ if part[-1].isdecimal():
205
+ part = part[:-2] + "." + part[-1] + part[-2]
206
+ # Normalize the size suffixes
207
+ if len(part) > 1 and part[-2].isdecimal():
208
+ if part[-1] in "kmbt":
209
+ part = part[:-1] + part[-1].upper()
210
+ if total_params != 0:
211
+ try:
212
+ label_params = float(part[:-1]) * pow(1000, " KMBT".find(part[-1]))
213
+ # Only use it as a size label if it's close or bigger than the model size
214
+ # Note that LoRA adapters don't necessarily include all layers,
215
+ # so this is why bigger label sizes are accepted.
216
+ # Do not use the size label when it's smaller than 1/8 of the model size
217
+ if (total_params < 0 and label_params < abs(total_params) // 8) or (
218
+ # Check both directions when the current model isn't a LoRA adapter
219
+ total_params > 0 and abs(label_params - total_params) > 7 * total_params // 8
220
+ ):
221
+ # Likely a context length
222
+ name_types[i].add("finetune")
223
+ # Lowercase the size when it's a context length
224
+ part = part[:-1] + part[-1].lower()
225
+ except ValueError:
226
+ # Failed to convert the size label to float, use it anyway
227
+ pass
228
+ if len(name_types[i]) == 0:
229
+ name_types[i].add("size_label")
230
+ name_parts[i] = part
231
+ # Some easy to recognize finetune names
232
+ elif i > 0 and re.fullmatch(r'chat|instruct|vision|lora', part, re.IGNORECASE):
233
+ if total_params < 0 and part.lower() == "lora":
234
+ # ignore redundant "lora" in the finetune part when the output is a lora adapter
235
+ name_types[i].add("type")
236
+ else:
237
+ name_types[i].add("finetune")
238
+
239
+ # Ignore word-based size labels when there is at least a number-based one present
240
+ # TODO: should word-based size labels always be removed instead?
241
+ if any(c.isdecimal() for n, t in zip(name_parts, name_types) if "size_label" in t for c in n):
242
+ for n, t in zip(name_parts, name_types):
243
+ if "size_label" in t:
244
+ if all(c.isalpha() for c in n):
245
+ t.remove("size_label")
246
+
247
+ at_start = True
248
+ # Find the basename through the annotated name
249
+ for part, t in zip(name_parts, name_types):
250
+ if at_start and ((len(t) == 0 and part[0].isalpha()) or "version" in t):
251
+ t.add("basename")
252
+ else:
253
+ if at_start:
254
+ at_start = False
255
+ if len(t) == 0:
256
+ t.add("finetune")
257
+
258
+ # Remove the basename annotation from trailing version
259
+ for part, t in zip(reversed(name_parts), reversed(name_types)):
260
+ if "basename" in t and len(t) > 1:
261
+ t.remove("basename")
262
+ else:
263
+ break
264
+
265
+ basename = "-".join(n for n, t in zip(name_parts, name_types) if "basename" in t) or None
266
+ # Deduplicate size labels using order-preserving 'dict' ('set' seems to sort the keys)
267
+ size_label = "-".join(dict.fromkeys(s for s, t in zip(name_parts, name_types) if "size_label" in t).keys()) or None
268
+ finetune = "-".join(f for f, t in zip(name_parts, name_types) if "finetune" in t) or None
269
+ # TODO: should the basename version always be excluded?
270
+ # NOTE: multiple finetune versions are joined together
271
+ version = "-".join(v for v, t, in zip(name_parts, name_types) if "version" in t and "basename" not in t) or None
272
+
273
+ if size_label is None and finetune is None and version is None:
274
+ # Too ambiguous, output nothing
275
+ basename = None
276
+
277
+ return model_full_name_component, org_component, basename, finetune, version, size_label
278
+
279
+ @staticmethod
280
+ def apply_metadata_heuristic(metadata: Metadata, model_card: Optional[dict] = None, hf_params: Optional[dict] = None, model_path: Optional[Path] = None, total_params: int = 0) -> Metadata:
281
+ # Reference Model Card Metadata: https://github.com/huggingface/hub-docs/blob/main/modelcard.md?plain=1
282
+
283
+ # Model Card Heuristics
284
+ ########################
285
+ if model_card is not None:
286
+
287
+ if "model_name" in model_card and metadata.name is None:
288
+ # Not part of huggingface model card standard but notice some model creator using it
289
+ # such as TheBloke in 'TheBloke/Mistral-7B-Instruct-v0.2-GGUF'
290
+ metadata.name = model_card.get("model_name")
291
+
292
+ if "model_creator" in model_card and metadata.author is None:
293
+ # Not part of huggingface model card standard but notice some model creator using it
294
+ # such as TheBloke in 'TheBloke/Mistral-7B-Instruct-v0.2-GGUF'
295
+ metadata.author = model_card.get("model_creator")
296
+
297
+ if "model_type" in model_card and metadata.basename is None:
298
+ # Not part of huggingface model card standard but notice some model creator using it
299
+ # such as TheBloke in 'TheBloke/Mistral-7B-Instruct-v0.2-GGUF'
300
+ metadata.basename = model_card.get("model_type")
301
+
302
+ if "base_model" in model_card:
303
+ # This represents the parent models that this is based on
304
+ # Example: stabilityai/stable-diffusion-xl-base-1.0. Can also be a list (for merges)
305
+ # Example of merges: https://huggingface.co/EmbeddedLLM/Mistral-7B-Merge-14-v0.1/blob/main/README.md
306
+ metadata_base_models = []
307
+ base_model_value = model_card.get("base_model", None)
308
+
309
+ if base_model_value is not None:
310
+ if isinstance(base_model_value, str):
311
+ metadata_base_models.append(base_model_value)
312
+ elif isinstance(base_model_value, list):
313
+ metadata_base_models.extend(base_model_value)
314
+
315
+ if metadata.base_models is None:
316
+ metadata.base_models = []
317
+
318
+ for model_id in metadata_base_models:
319
+ # NOTE: model size of base model is assumed to be similar to the size of the current model
320
+ model_full_name_component, org_component, basename, finetune, version, size_label = Metadata.get_model_id_components(model_id, total_params)
321
+ base_model = {}
322
+ if model_full_name_component is not None:
323
+ base_model["name"] = Metadata.id_to_title(model_full_name_component)
324
+ if org_component is not None:
325
+ base_model["organization"] = Metadata.id_to_title(org_component)
326
+ if version is not None:
327
+ base_model["version"] = version
328
+ if org_component is not None and model_full_name_component is not None:
329
+ base_model["repo_url"] = f"https://huggingface.co/{org_component}/{model_full_name_component}"
330
+ metadata.base_models.append(base_model)
331
+
332
+ if "license" in model_card and metadata.license is None:
333
+ metadata.license = model_card.get("license")
334
+
335
+ if "license_name" in model_card and metadata.license_name is None:
336
+ metadata.license_name = model_card.get("license_name")
337
+
338
+ if "license_link" in model_card and metadata.license_link is None:
339
+ metadata.license_link = model_card.get("license_link")
340
+
341
+ tags_value = model_card.get("tags", None)
342
+ if tags_value is not None:
343
+
344
+ if metadata.tags is None:
345
+ metadata.tags = []
346
+
347
+ if isinstance(tags_value, str):
348
+ metadata.tags.append(tags_value)
349
+ elif isinstance(tags_value, list):
350
+ metadata.tags.extend(tags_value)
351
+
352
+ pipeline_tags_value = model_card.get("pipeline_tag", None)
353
+ if pipeline_tags_value is not None:
354
+
355
+ if metadata.tags is None:
356
+ metadata.tags = []
357
+
358
+ if isinstance(pipeline_tags_value, str):
359
+ metadata.tags.append(pipeline_tags_value)
360
+ elif isinstance(pipeline_tags_value, list):
361
+ metadata.tags.extend(pipeline_tags_value)
362
+
363
+ language_value = model_card.get("languages", model_card.get("language", None))
364
+ if language_value is not None:
365
+
366
+ if metadata.languages is None:
367
+ metadata.languages = []
368
+
369
+ if isinstance(language_value, str):
370
+ metadata.languages.append(language_value)
371
+ elif isinstance(language_value, list):
372
+ metadata.languages.extend(language_value)
373
+
374
+ dataset_value = model_card.get("datasets", model_card.get("dataset", None))
375
+ if dataset_value is not None:
376
+
377
+ if metadata.datasets is None:
378
+ metadata.datasets = []
379
+
380
+ if isinstance(dataset_value, str):
381
+ metadata.datasets.append(dataset_value)
382
+ elif isinstance(dataset_value, list):
383
+ metadata.datasets.extend(dataset_value)
384
+
385
+ # Hugging Face Parameter Heuristics
386
+ ####################################
387
+
388
+ if hf_params is not None:
389
+
390
+ hf_name_or_path = hf_params.get("_name_or_path")
391
+ if hf_name_or_path is not None and hf_name_or_path.count('/') <= 1:
392
+ # Use _name_or_path only if its actually a model name and not some computer path
393
+ # e.g. 'meta-llama/Llama-2-7b-hf'
394
+ model_id = hf_name_or_path
395
+ model_full_name_component, org_component, basename, finetune, version, size_label = Metadata.get_model_id_components(model_id, total_params)
396
+ if metadata.name is None and model_full_name_component is not None:
397
+ metadata.name = Metadata.id_to_title(model_full_name_component)
398
+ if metadata.organization is None and org_component is not None:
399
+ metadata.organization = Metadata.id_to_title(org_component)
400
+ if metadata.basename is None and basename is not None:
401
+ metadata.basename = basename
402
+ if metadata.finetune is None and finetune is not None:
403
+ metadata.finetune = finetune
404
+ if metadata.version is None and version is not None:
405
+ metadata.version = version
406
+ if metadata.size_label is None and size_label is not None:
407
+ metadata.size_label = size_label
408
+
409
+ # Directory Folder Name Fallback Heuristics
410
+ ############################################
411
+ if model_path is not None:
412
+ model_id = model_path.name
413
+ model_full_name_component, org_component, basename, finetune, version, size_label = Metadata.get_model_id_components(model_id, total_params)
414
+ if metadata.name is None and model_full_name_component is not None:
415
+ metadata.name = Metadata.id_to_title(model_full_name_component)
416
+ if metadata.organization is None and org_component is not None:
417
+ metadata.organization = Metadata.id_to_title(org_component)
418
+ if metadata.basename is None and basename is not None:
419
+ metadata.basename = basename
420
+ if metadata.finetune is None and finetune is not None:
421
+ metadata.finetune = finetune
422
+ if metadata.version is None and version is not None:
423
+ metadata.version = version
424
+ if metadata.size_label is None and size_label is not None:
425
+ metadata.size_label = size_label
426
+
427
+ return metadata
428
+
429
+ def set_gguf_meta_model(self, gguf_writer: gguf.GGUFWriter):
430
+ assert self.name is not None
431
+ gguf_writer.add_name(self.name)
432
+
433
+ if self.author is not None:
434
+ gguf_writer.add_author(self.author)
435
+ if self.version is not None:
436
+ gguf_writer.add_version(self.version)
437
+ if self.organization is not None:
438
+ gguf_writer.add_organization(self.organization)
439
+
440
+ if self.finetune is not None:
441
+ gguf_writer.add_finetune(self.finetune)
442
+ if self.basename is not None:
443
+ gguf_writer.add_basename(self.basename)
444
+
445
+ if self.description is not None:
446
+ gguf_writer.add_description(self.description)
447
+ if self.quantized_by is not None:
448
+ gguf_writer.add_quantized_by(self.quantized_by)
449
+
450
+ if self.size_label is not None:
451
+ gguf_writer.add_size_label(self.size_label)
452
+
453
+ if self.license is not None:
454
+ gguf_writer.add_license(self.license)
455
+ if self.license_name is not None:
456
+ gguf_writer.add_license_name(self.license_name)
457
+ if self.license_link is not None:
458
+ gguf_writer.add_license_link(self.license_link)
459
+
460
+ if self.url is not None:
461
+ gguf_writer.add_url(self.url)
462
+ if self.doi is not None:
463
+ gguf_writer.add_doi(self.doi)
464
+ if self.uuid is not None:
465
+ gguf_writer.add_uuid(self.uuid)
466
+ if self.repo_url is not None:
467
+ gguf_writer.add_repo_url(self.repo_url)
468
+
469
+ if self.source_url is not None:
470
+ gguf_writer.add_source_url(self.source_url)
471
+ if self.source_doi is not None:
472
+ gguf_writer.add_source_doi(self.source_doi)
473
+ if self.source_uuid is not None:
474
+ gguf_writer.add_source_uuid(self.source_uuid)
475
+ if self.source_repo_url is not None:
476
+ gguf_writer.add_source_repo_url(self.source_repo_url)
477
+
478
+ if self.base_models is not None:
479
+ gguf_writer.add_base_model_count(len(self.base_models))
480
+ for key, base_model_entry in enumerate(self.base_models):
481
+ if "name" in base_model_entry:
482
+ gguf_writer.add_base_model_name(key, base_model_entry["name"])
483
+ if "author" in base_model_entry:
484
+ gguf_writer.add_base_model_author(key, base_model_entry["author"])
485
+ if "version" in base_model_entry:
486
+ gguf_writer.add_base_model_version(key, base_model_entry["version"])
487
+ if "organization" in base_model_entry:
488
+ gguf_writer.add_base_model_organization(key, base_model_entry["organization"])
489
+ if "url" in base_model_entry:
490
+ gguf_writer.add_base_model_url(key, base_model_entry["url"])
491
+ if "doi" in base_model_entry:
492
+ gguf_writer.add_base_model_doi(key, base_model_entry["doi"])
493
+ if "uuid" in base_model_entry:
494
+ gguf_writer.add_base_model_uuid(key, base_model_entry["uuid"])
495
+ if "repo_url" in base_model_entry:
496
+ gguf_writer.add_base_model_repo_url(key, base_model_entry["repo_url"])
497
+
498
+ if self.tags is not None:
499
+ gguf_writer.add_tags(self.tags)
500
+ if self.languages is not None:
501
+ gguf_writer.add_languages(self.languages)
502
+ if self.datasets is not None:
503
+ gguf_writer.add_datasets(self.datasets)
@@ -0,0 +1,69 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Literal
4
+
5
+
6
+ def fill_templated_filename(filename: str, output_type: str | None) -> str:
7
+ # Given a file name fill in any type templates e.g. 'some-model-name.{ftype}.gguf'
8
+ ftype_lowercase: str = output_type.lower() if output_type is not None else ""
9
+ ftype_uppercase: str = output_type.upper() if output_type is not None else ""
10
+ return filename.format(ftype_lowercase,
11
+ outtype=ftype_lowercase, ftype=ftype_lowercase,
12
+ OUTTYPE=ftype_uppercase, FTYPE=ftype_uppercase)
13
+
14
+
15
+ def model_weight_count_rounded_notation(model_params_count: int, min_digits: int = 2) -> str:
16
+ if model_params_count > 1e12 :
17
+ # Trillions Of Parameters
18
+ scaled_model_params = model_params_count * 1e-12
19
+ scale_suffix = "T"
20
+ elif model_params_count > 1e9 :
21
+ # Billions Of Parameters
22
+ scaled_model_params = model_params_count * 1e-9
23
+ scale_suffix = "B"
24
+ elif model_params_count > 1e6 :
25
+ # Millions Of Parameters
26
+ scaled_model_params = model_params_count * 1e-6
27
+ scale_suffix = "M"
28
+ else:
29
+ # Thousands Of Parameters
30
+ scaled_model_params = model_params_count * 1e-3
31
+ scale_suffix = "K"
32
+
33
+ fix = max(min_digits - len(str(round(scaled_model_params)).lstrip('0')), 0)
34
+
35
+ return f"{scaled_model_params:.{fix}f}{scale_suffix}"
36
+
37
+
38
+ def size_label(total_params: int, shared_params: int, expert_params: int, expert_count: int) -> str:
39
+
40
+ if expert_count > 0:
41
+ pretty_size = model_weight_count_rounded_notation(abs(shared_params) + abs(expert_params), min_digits=2)
42
+ size_class = f"{expert_count}x{pretty_size}"
43
+ else:
44
+ size_class = model_weight_count_rounded_notation(abs(total_params), min_digits=2)
45
+
46
+ return size_class
47
+
48
+
49
+ def naming_convention(model_name: str | None, base_name: str | None, finetune_string: str | None, version_string: str | None, size_label: str | None, output_type: str | None, model_type: Literal['vocab', 'LoRA'] | None = None) -> str:
50
+ # Reference: https://github.com/ggerganov/ggml/blob/master/docs/gguf.md#gguf-naming-convention
51
+
52
+ if base_name is not None:
53
+ name = base_name.strip().replace(' ', '-').replace('/', '-')
54
+ elif model_name is not None:
55
+ name = model_name.strip().replace(' ', '-').replace('/', '-')
56
+ else:
57
+ name = "ggml-model"
58
+
59
+ parameters = f"-{size_label}" if size_label is not None else ""
60
+
61
+ finetune = f"-{finetune_string.strip().replace(' ', '-')}" if finetune_string is not None else ""
62
+
63
+ version = f"-{version_string.strip().replace(' ', '-')}" if version_string is not None else ""
64
+
65
+ encoding = f"-{output_type.strip().replace(' ', '-').upper()}" if output_type is not None else ""
66
+
67
+ kind = f"-{model_type.strip().replace(' ', '-')}" if model_type is not None else ""
68
+
69
+ return f"{name}{parameters}{finetune}{version}{encoding}{kind}"
bigdl/cpp/libs/baby-llama CHANGED
Binary file
bigdl/cpp/libs/batched CHANGED
Binary file
Binary file
bigdl/cpp/libs/benchmark CHANGED
Binary file
bigdl/cpp/libs/embedding CHANGED
Binary file
bigdl/cpp/libs/gguf CHANGED
Binary file
bigdl/cpp/libs/imatrix CHANGED
Binary file
Binary file
bigdl/cpp/libs/llava-cli CHANGED
Binary file
bigdl/cpp/libs/lookahead CHANGED
Binary file
bigdl/cpp/libs/lookup CHANGED
Binary file
Binary file
bigdl/cpp/libs/main CHANGED
Binary file
bigdl/cpp/libs/ollama CHANGED
Binary file
bigdl/cpp/libs/perplexity CHANGED
Binary file
bigdl/cpp/libs/quantize CHANGED
Binary file
Binary file
Binary file
bigdl/cpp/libs/server CHANGED
Binary file
Binary file
bigdl/cpp/libs/tokenize CHANGED
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bigdl-core-cpp
3
- Version: 2.5.0b20240729
3
+ Version: 2.5.0b20240731
4
4
  Summary: Large Language Model Develop Toolkit
5
5
  Author: BigDL Authors
6
6
  License: Apache License, Version 2.0
@@ -0,0 +1,45 @@
1
+ bigdl/cpp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ bigdl/cpp/convert-hf-to-gguf.py,sha256=1wAaTiqtAsnA_4k10TCzDSp4KTZ_mldv6pY47z5gg7M,166672
3
+ bigdl/cpp/convert.py,sha256=XMMcpfWHwEAAWzwLXe9mmJTU7cMvcyw8g2BFctfZnvI,69417
4
+ bigdl/cpp/cli/init-llama-cpp,sha256=qpIwMQc2Vb11fmovXFJKefp5iD1tQMfL8Ma7Y3Ebguk,400
5
+ bigdl/cpp/cli/init-ollama,sha256=5eg4DsWg87iysFRh7leawr6H47F_sHydwL5we6fUG6o,193
6
+ bigdl/cpp/gguf-py/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ bigdl/cpp/gguf-py/gguf/__init__.py,sha256=LUfJeRbrLY6TgwI0rLw_qo8klu7GgYB8Ycu8H4V0eb8,218
8
+ bigdl/cpp/gguf-py/gguf/constants.py,sha256=WRloarpYU4sc0tIi8aDgIh6xb6Ox0CPLCiPa9Yzzm2Q,46902
9
+ bigdl/cpp/gguf-py/gguf/gguf.py,sha256=MzR6GNwyrWBN3w-o995FY0qX8U3J9Mbinu9HAMEjx8g,477
10
+ bigdl/cpp/gguf-py/gguf/gguf_reader.py,sha256=5yv15RSKLfz9ViQd2e-vQxzXEdCGqgJfGfoBbzPYTHw,12364
11
+ bigdl/cpp/gguf-py/gguf/gguf_writer.py,sha256=HqxGAplbhGDgn9bELLFFh3Nf15Gg16BOTVvhOMKe6GM,34612
12
+ bigdl/cpp/gguf-py/gguf/lazy.py,sha256=yMcMTIrlwpQrX9m8YSRdvyHsNupHZMSj1RsjAAPrxqE,8527
13
+ bigdl/cpp/gguf-py/gguf/metadata.py,sha256=HNu6fzuLLSzQ_K_xJkKqtT5Tni3kGESj67BZ2uPNajg,24851
14
+ bigdl/cpp/gguf-py/gguf/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
+ bigdl/cpp/gguf-py/gguf/quants.py,sha256=dI6JsSpaSzfdz7OwfqH1kvK98M_Ax8d6NMNYY5pyoQM,4354
16
+ bigdl/cpp/gguf-py/gguf/tensor_mapping.py,sha256=1tNoM-XXvD8JaStxt39HBRe_obCWawHfTFVCWXRe9Zk,30147
17
+ bigdl/cpp/gguf-py/gguf/utility.py,sha256=xEIfT3CphqAyI56A5XZQDMti2XGG5k6kxm5bjf_Vn-E,2933
18
+ bigdl/cpp/gguf-py/gguf/vocab.py,sha256=vsRrPQ6RafirhBmMp9h3YGZh_tqEjeg7S2hiLvMv7Ys,6847
19
+ bigdl/cpp/libs/baby-llama,sha256=x-PQNe0GxJbDSD5pYoEcJBUzv3tf63XWE396SqIMOxQ,14319136
20
+ bigdl/cpp/libs/batched,sha256=X5bbE0mB17eK5kskOzg5ssrz1CUTmD8si7zlgteIP7Y,14239608
21
+ bigdl/cpp/libs/batched-bench,sha256=lRxVbjMvf7-b95nkjU49Z2_7z7O9RO1eOwAUcw-zyAA,14243864
22
+ bigdl/cpp/libs/benchmark,sha256=SgfXtC5EHFAKpapTP8iiJQcV3XpcqVhCjGqPqz8nhoU,1452712
23
+ bigdl/cpp/libs/embedding,sha256=h49RtXjuGFaQV8ny096q0aq_yf35qxGHJP31vzFBG0c,14239752
24
+ bigdl/cpp/libs/gguf,sha256=mg6C4eUeUxkQdKVqr1BQOXEEElYcx_0CowTpLailHns,12483008
25
+ bigdl/cpp/libs/imatrix,sha256=ecbxPAT5Bjd-fUsHGaQ3KK5bkCYVCszdhS9QfQkTJqg,14267608
26
+ bigdl/cpp/libs/llama-bench,sha256=ecRaeb3MFHQk2jeqOupUTtBPj9zJtNrhiBACTPCu_vY,14333248
27
+ bigdl/cpp/libs/llava-cli,sha256=DUPsSEMaZSseyIV0mGZ4yLeNq_VMeOl_3DQ07IbsYWs,14557832
28
+ bigdl/cpp/libs/lookahead,sha256=hevgvvQaBPO5QVK0p3D3Urotw_648DAQ2dkMz70QTAU,14252072
29
+ bigdl/cpp/libs/lookup,sha256=-RN86yJO85R14A62qSkZcgL8iWq0AmnPY1MekwmKspI,14271856
30
+ bigdl/cpp/libs/ls-sycl-device,sha256=O_KI8LD7x8stz9SbhuPkzm9fxBmqVHUFLejWyHHhwBg,12478752
31
+ bigdl/cpp/libs/main,sha256=wAhJeVkzI_ZbI8pI4sA4ezgHLZqCQQaRi-BhowT6dm4,14299192
32
+ bigdl/cpp/libs/ollama,sha256=7CQQkXkretFzJbtXE7__j-5JrmtGlwmlA7Vdg588JGc,47375400
33
+ bigdl/cpp/libs/perplexity,sha256=SMHuquYaN3jEl93TaqhBNq63JJiSO6gKP6256tXRGMQ,14340696
34
+ bigdl/cpp/libs/quantize,sha256=gH-Qcd7Epgr6CXRbo1XmESvmZf6wuY932dt2i_DGJng,14265984
35
+ bigdl/cpp/libs/quantize-stats,sha256=-IZdMCGAmCgUAJu_lpsQQ9gmoVGdvwVy2fQi3R29n7E,13780224
36
+ bigdl/cpp/libs/save-load-state,sha256=vWxwnoimWgb2LTq4Q2WohovU57UuAsh8aWmLxJEMpIQ,14239880
37
+ bigdl/cpp/libs/server,sha256=hvc6JhP2_LZ8kDoHHuWQ2QDsp04rkThXebIte7LD5EQ,15097272
38
+ bigdl/cpp/libs/speculative,sha256=TkTon3zcxvu7kT6HxknOBeZ-v0F2m0EgXMYeJccXTcY,14278112
39
+ bigdl/cpp/libs/tokenize,sha256=hUwr0spsvjV1IiDjyAX0uQpY4DR7lJc1lSbHCQVmyls,14239800
40
+ bigdl_core_cpp-2.5.0b20240731.data/scripts/init-llama-cpp,sha256=qpIwMQc2Vb11fmovXFJKefp5iD1tQMfL8Ma7Y3Ebguk,400
41
+ bigdl_core_cpp-2.5.0b20240731.data/scripts/init-ollama,sha256=5eg4DsWg87iysFRh7leawr6H47F_sHydwL5we6fUG6o,193
42
+ bigdl_core_cpp-2.5.0b20240731.dist-info/METADATA,sha256=O_UAO4dEDfQ98zW-vfO7pZBI8TgpApciW7di7ZGdtto,650
43
+ bigdl_core_cpp-2.5.0b20240731.dist-info/WHEEL,sha256=GHycjhgos9e5ojAyWZiFxz9HM8k84hAls6WqrsH8row,109
44
+ bigdl_core_cpp-2.5.0b20240731.dist-info/top_level.txt,sha256=iGuLfZARD_qANcIMfy0tbbrC3EtCg6BSiH8icc3dLWs,6
45
+ bigdl_core_cpp-2.5.0b20240731.dist-info/RECORD,,
@@ -1,43 +0,0 @@
1
- bigdl/cpp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- bigdl/cpp/convert-hf-to-gguf.py,sha256=1wAaTiqtAsnA_4k10TCzDSp4KTZ_mldv6pY47z5gg7M,166672
3
- bigdl/cpp/convert.py,sha256=XMMcpfWHwEAAWzwLXe9mmJTU7cMvcyw8g2BFctfZnvI,69417
4
- bigdl/cpp/cli/init-llama-cpp,sha256=qpIwMQc2Vb11fmovXFJKefp5iD1tQMfL8Ma7Y3Ebguk,400
5
- bigdl/cpp/cli/init-ollama,sha256=5eg4DsWg87iysFRh7leawr6H47F_sHydwL5we6fUG6o,193
6
- bigdl/cpp/gguf-py/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- bigdl/cpp/gguf-py/gguf/__init__.py,sha256=LUfJeRbrLY6TgwI0rLw_qo8klu7GgYB8Ycu8H4V0eb8,218
8
- bigdl/cpp/gguf-py/gguf/constants.py,sha256=WRloarpYU4sc0tIi8aDgIh6xb6Ox0CPLCiPa9Yzzm2Q,46902
9
- bigdl/cpp/gguf-py/gguf/gguf.py,sha256=MzR6GNwyrWBN3w-o995FY0qX8U3J9Mbinu9HAMEjx8g,477
10
- bigdl/cpp/gguf-py/gguf/gguf_reader.py,sha256=5yv15RSKLfz9ViQd2e-vQxzXEdCGqgJfGfoBbzPYTHw,12364
11
- bigdl/cpp/gguf-py/gguf/gguf_writer.py,sha256=HqxGAplbhGDgn9bELLFFh3Nf15Gg16BOTVvhOMKe6GM,34612
12
- bigdl/cpp/gguf-py/gguf/lazy.py,sha256=yMcMTIrlwpQrX9m8YSRdvyHsNupHZMSj1RsjAAPrxqE,8527
13
- bigdl/cpp/gguf-py/gguf/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- bigdl/cpp/gguf-py/gguf/quants.py,sha256=dI6JsSpaSzfdz7OwfqH1kvK98M_Ax8d6NMNYY5pyoQM,4354
15
- bigdl/cpp/gguf-py/gguf/tensor_mapping.py,sha256=1tNoM-XXvD8JaStxt39HBRe_obCWawHfTFVCWXRe9Zk,30147
16
- bigdl/cpp/gguf-py/gguf/vocab.py,sha256=vsRrPQ6RafirhBmMp9h3YGZh_tqEjeg7S2hiLvMv7Ys,6847
17
- bigdl/cpp/libs/baby-llama,sha256=SKKPIkcEV-ipA3cwYJty25Z1NHLtaD7k93LdQ0lG3tc,14319136
18
- bigdl/cpp/libs/batched,sha256=55MsxwGU3fxxEBHtIRoIn_WZs6wuHfBVZNES6DVO210,14239608
19
- bigdl/cpp/libs/batched-bench,sha256=VY_JS6QhN3XbTuRwybXRXod4wJZJdfE80BlAycnhNsg,14243864
20
- bigdl/cpp/libs/benchmark,sha256=9j1ysoHD7s-OZtFIQ0oGkJJJ42FYteh37xXqkuXTWkg,1452712
21
- bigdl/cpp/libs/embedding,sha256=Mf_80cjxbHFUssSatQUmNR7wBu6hkQ3D0X5WDD9DBno,14239752
22
- bigdl/cpp/libs/gguf,sha256=yjkKfVa4uqW6n0FDx1AatwCDv5e_HWbAOr3oF2RFxyQ,12483008
23
- bigdl/cpp/libs/imatrix,sha256=NZm1SqtlvbJWtVjOKFWqo2_KdLnYUU92kAsB8u8d9Rk,14267608
24
- bigdl/cpp/libs/llama-bench,sha256=f25Cu1DvrBrmFijvdmXPQ9c1_M24LFFd3kbwaP7iQZY,14333248
25
- bigdl/cpp/libs/llava-cli,sha256=R-beNkh0fZdMcqlFypD0lXfABY3jCMkx-KJ2Jf2iJ-g,14557832
26
- bigdl/cpp/libs/lookahead,sha256=SsiP9Z3owoQWBKu8QD9ykuA_5doyVEQUvJ9ANUOoOQw,14252072
27
- bigdl/cpp/libs/lookup,sha256=4zws0ehtialYhQWbq3eJb5UpSV5GdDUYYISvl3OPgK0,14271856
28
- bigdl/cpp/libs/ls-sycl-device,sha256=nSbCmRjzxlFBXUyQHx3_fp_HCpqhc_p6Gn6j4GqWc1I,12478752
29
- bigdl/cpp/libs/main,sha256=jzjHiMjjUHrIX7UkX1yI4wPJA5MNYjAUGkOGpEGc1Jc,14299192
30
- bigdl/cpp/libs/ollama,sha256=dlOV0VZ9CCJ-TeGBAZhuAYjfT5K9zpJnGzMgiXZgtZQ,47375392
31
- bigdl/cpp/libs/perplexity,sha256=d6fWNkaNk7ZD8aootAMQJ5Jlkg28D3HQgKm3Jri7bI4,14340696
32
- bigdl/cpp/libs/quantize,sha256=osgig6LdQMADRxvNzVnbVWeXIoOcjA1bISCefs0iEKo,14265984
33
- bigdl/cpp/libs/quantize-stats,sha256=hNxZWNLrd4-hKPbrVnbgYWE1antuNZ-YXCPOHqUntss,13780224
34
- bigdl/cpp/libs/save-load-state,sha256=DwRNXqjOEpi1DYQyhHVr5MuZbCYKFfXSd5hwmdCktf0,14239880
35
- bigdl/cpp/libs/server,sha256=sGsNoRgl_Bp_qqXcRBFtKY40L1e7ZKaACqHeUC5poCk,15097272
36
- bigdl/cpp/libs/speculative,sha256=0AAmhAPWq1nzy5vi8BgTDZh14g_f9UfeYPPniGE9Y6M,14278112
37
- bigdl/cpp/libs/tokenize,sha256=ggh5Y8l5c6z7NSNlsFPPEEBJpdhRfwEH9oImr2DlyNM,14239800
38
- bigdl_core_cpp-2.5.0b20240729.data/scripts/init-llama-cpp,sha256=qpIwMQc2Vb11fmovXFJKefp5iD1tQMfL8Ma7Y3Ebguk,400
39
- bigdl_core_cpp-2.5.0b20240729.data/scripts/init-ollama,sha256=5eg4DsWg87iysFRh7leawr6H47F_sHydwL5we6fUG6o,193
40
- bigdl_core_cpp-2.5.0b20240729.dist-info/METADATA,sha256=xYrtStu_ZFFWxaQk5Ux1R9aHOWd_0l_W3ZLdBqGH5NM,650
41
- bigdl_core_cpp-2.5.0b20240729.dist-info/WHEEL,sha256=GHycjhgos9e5ojAyWZiFxz9HM8k84hAls6WqrsH8row,109
42
- bigdl_core_cpp-2.5.0b20240729.dist-info/top_level.txt,sha256=iGuLfZARD_qANcIMfy0tbbrC3EtCg6BSiH8icc3dLWs,6
43
- bigdl_core_cpp-2.5.0b20240729.dist-info/RECORD,,