To json

GPU Poor POV: GGUF snippet

!git clone https://github.com/ggerganov/llama.cpp
!cd llama.cpp && git pull && make clean && LLAMA_CUBLAS=1 make
%cd llama.cpp
!pip install -r llama.cpp/requirements.txt
!pip install -U pip
!pip install -U huggingface_hub
MODEL_ID = 'PotatoOff/Michel-13B'
import os
MODEL_NAME: str = MODEL_ID.split('/')[-1]
RNAME: str = f'{MODEL_NAME}-GGUF'
ORIG_PATH: str = f'{MODEL_NAME}/orig'
QUANT_PATH: str = f'{MODEL_NAME}/quant'
WTOKEN: str = "hf_itsnotmytoken"
os.makedirs(MODEL_NAME, exist_ok=True)
os.makedirs(ORIG_PATH, exist_ok = True)
os.makedirs(QUANT_PATH, exist_ok= True)



from huggingface_hub import snapshot_download
snapshot_download(repo_id=MODEL_ID, local_dir=ORIG_PATH,
                  local_dir_use_symlinks=False, revision="main", token=WTOKEN)
fp16 = f"{QUANT_PATH}/{MODEL_NAME.lower()}.fp16.bin"
!python /notebooks/llama.cpp/convert.py /notebooks/{ORIG_PATH} --outtype f16 --outfile {fp16}

QUANTIZATION_METHODS = ["q4_k_m", "q5_k_m", 'q6_k', 'q3_k_s', 'q8_0']

for method in QUANTIZATION_METHODS:
    qtype = f"{QUANT_PATH}/{MODEL_NAME.lower()}.{method.upper()}.gguf"
    !/notebooks/llama.cpp/quantize {fp16} {qtype} {method}


!llama.cpp/main -m /notebooks/{QUANT_PATH}/{MODEL_NAME.lower()}.Q5_K_M.gguf -n 128 -p "User: Tell me story about what is an quantization and what do we need to build." > {MODEL_NAME}/questions.txt
!llama.cpp/main -m /notebooks/{QUANT_PATH}/{MODEL_NAME.lower()}.Q5_K_M.gguf -n 128 -p "User: Tell me story about what is an quantization and what do we need to build." > {MODEL_NAME}/questions.txt
r = f"""
---
license: openrail
pipeline_tag: text-generation
library_name: transformers
language:
- zh
- en
---


## Original model card 

Buy me a coffee if you like this project ;)
<a href="https://www.buymeacoffee.com/s3nh"><img src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-1.svg" alt=""></a>

#### Description 

GGUF Format model files for [This project](https://huggingface.co/{MODEL_ID}).

### GGUF Specs 

GGUF is a format based on the existing GGJT, but makes a few changes to the format to make it more extensible and easier to use. The following features are desired:

Single-file deployment: they can be easily distributed and loaded, and do not require any external files for additional information.
Extensible: new features can be added to GGML-based executors/new information can be added to GGUF models without breaking compatibility with existing models.
mmap compatibility: models can be loaded using mmap for fast loading and saving.
Easy to use: models can be easily loaded and saved using a small amount of code, with no need for external libraries, regardless of the language used.
Full information: all information needed to load a model is contained in the model file, and no additional information needs to be provided by the user.
The key difference between GGJT and GGUF is the use of a key-value structure for the hyperparameters (now referred to as metadata), rather than a list of untyped values. 
This allows for new metadata to be added without breaking compatibility with existing models, and to annotate the model with additional information that may be useful for
inference or for identifying the model.



### inference 


{data}

# Original model card
""" 
api = HfApi()
with open(f'{QUANT_PATH}/README.md', 'w') as outfile:
    outfile.writelines(r)
import pathlib
gguf_files = list(pathlib.Path(f'/notebooks/{QUANT_PATH}').rglob('*.gguf'))
if len(gguf_files) > 0:

    try:
        create_repo(RNAME, token=WTOKEN)

        TYPE = 'model'
        api.upload_folder(
            folder_path = f'/notebooks/{QUANT_PATH}', 
            repo_id = f's3nh/{RNAME}',
            repo_type=TYPE,
            path_in_repo = "./",
            token= WTOKEN
        )
        !rm -rf {QUANT_PATH}/
        !rm -rf {ORIG_PATH}/
        !rm -rf {MODEL_NAME}/
    except:
        TYPE = 'model'
        api.upload_folder(
            folder_path = f'/notebooks/{QUANT_PATH}', 
            repo_id = f's3nh/{RNAME}',
            repo_type=TYPE,
            path_in_repo = "./",
            token= WTOKEN
        )
        !rm -rf {QUANT_PATH}/
        !rm -rf {ORIG_PATH}/
        !rm -rf {MODEL_NAME}/
else:
    print("Something went wrong")