Skip to content

Commit d0af335

Browse files
authored
Merge pull request #43 from Supahands/feat/upload-to-hf
added upload_to_hf method
2 parents 9d9ca6e + 0d65b81 commit d0af335

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

hugging_face_to_guff.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ def convert_to_gguf(
232232
model_files,
233233
f"{username}/{modelname}-gguf",
234234
source_model_id,
235-
quanttype,
236235
private,
237236
)
238237

@@ -241,21 +240,18 @@ def convert_to_gguf(
241240
raise
242241

243242
@method()
244-
def upload_to_hf(self, file_path: str, repo_id: str, source_model_id: str, quant_type: str, private: bool = False):
243+
def upload_to_hf(self, model_files: List[tuple], repo_id: str, source_model_id: str, private: bool = False):
245244
logger.info("Reloading volume before upload...")
246245
volume.reload()
247246

248-
logger.info(f"Uploading GGUF model to HuggingFace repo {repo_id}...")
247+
logger.info(f"Uploading GGUF models to HuggingFace repo {repo_id}...")
249248
from huggingface_hub import HfApi, ModelCard
250249
from textwrap import dedent
251250

252251
try:
253252
api = HfApi()
254-
255-
# Create repo first
256253
api.create_repo(repo_id, exist_ok=True, private=private, repo_type="model")
257254

258-
# Generate model card
259255
try:
260256
card = ModelCard.load(source_model_id)
261257
except Exception:
@@ -266,31 +262,37 @@ def upload_to_hf(self, file_path: str, repo_id: str, source_model_id: str, quant
266262
card.data.tags.extend(["llama-cpp", "gguf"])
267263
card.data.base_model = source_model_id
268264

269-
filename = os.path.basename(file_path)
270-
card.text = dedent(
271-
f"""
265+
# Generate model card with all versions
266+
versions_text = "\n".join([
267+
f"- `{os.path.basename(file)}` ({quant_type})"
268+
for file, quant_type in model_files
269+
])
270+
271+
card.text = dedent(f"""
272272
# {repo_id}
273273
This model was converted to GGUF format from [`{source_model_id}`](https://huggingface.co/{source_model_id}) using llama.cpp.
274274
Refer to the [original model card](https://huggingface.co/{source_model_id}) for more details on the model.
275275
276+
## Available Versions
277+
{versions_text}
278+
276279
## Use with llama.cpp
280+
Replace `FILENAME` with one of the above filenames.
277281
278282
### CLI:
279283
```bash
280-
llama-cli --hf-repo {repo_id} --hf-file {filename} -p "Your prompt here"
284+
llama-cli --hf-repo {repo_id} --hf-file FILENAME -p "Your prompt here"
281285
```
282286
283287
### Server:
284288
```bash
285-
llama-server --hf-repo {repo_id} --hf-file {filename} -c 2048
289+
llama-server --hf-repo {repo_id} --hf-file FILENAME -c 2048
286290
```
287291
288292
## Model Details
289-
- **Quantization Type:** {quant_type}
290293
- **Original Model:** [{source_model_id}](https://huggingface.co/{source_model_id})
291294
- **Format:** GGUF
292-
"""
293-
)
295+
""")
294296

295297
# Save and upload README
296298
readme_path = "/tmp/README.md"
@@ -301,13 +303,15 @@ def upload_to_hf(self, file_path: str, repo_id: str, source_model_id: str, quant
301303
repo_id=repo_id
302304
)
303305

304-
# Upload the model file
305-
logger.info(f"Uploading quantized model: {file_path}")
306-
api.upload_file(
307-
path_or_fileobj=file_path,
308-
path_in_repo=filename,
309-
repo_id=repo_id
310-
)
306+
# Upload all model files
307+
for file_path, _ in model_files:
308+
filename = os.path.basename(file_path)
309+
logger.info(f"Uploading quantized model: {filename}")
310+
api.upload_file(
311+
path_or_fileobj=file_path,
312+
path_in_repo=filename,
313+
repo_id=repo_id
314+
)
311315

312316
# Upload imatrix.dat if it exists
313317
imatrix_path = "/root/llama.cpp/imatrix.dat"

0 commit comments

Comments
 (0)