File size: 1,369 Bytes
2fcc4a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Shared, editable GGUF usage guide for all release cards."""
from pathlib import Path


def enhance_gguf_card(card, repo, model, llama_revision):
    usage = (Path(__file__).parent / "GGUF-USAGE.md").read_text(encoding="utf-8")
    for key, value in {"__REPO__": repo, "__MODEL__": model, "__LLAMA_REV__": llama_revision}.items():
        usage = usage.replace(key, value)
    begin, end = "<!-- GGUF-USAGE-BEGIN -->", "<!-- GGUF-USAGE-END -->"
    section = begin + "\n" + usage.rstrip() + "\n" + end + "\n\n"
    if begin in card:
        start = card.index(begin)
        stop = card.index(end, start) + len(end)
        return card[:start] + section.rstrip() + card[stop:]
    # Replace the old short run recipe with the full guide before evaluations.
    if "\n## Run\n" in card:
        start = card.index("\n## Run\n")
        stops = [card.find(marker, start) for marker in ("\nOriginal model and implementation:", "\n## Attribution")]
        stops = [stop for stop in stops if stop >= 0]
        if not stops:
            raise ValueError("Cannot locate end of old GGUF run instructions")
        card = card[:start] + "\n" + card[min(stops):]
    for marker in ("## Validation\n", "## Measured checks\n"):
        if marker in card:
            return card.replace(marker, section + marker, 1)
    raise ValueError("Cannot locate GGUF evaluation section")