Text Generation
llama-cpp-python
GGUF
English
code-generation
coding-assistant
llama.cpp
qwen2.5
python
javascript
fine-tuned
conversational
Instructions to use neuralbroker/blitzkode with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use neuralbroker/blitzkode with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="neuralbroker/blitzkode", filename="blitzkode.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - llama-cpp-python
How to use neuralbroker/blitzkode with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="neuralbroker/blitzkode", filename="blitzkode.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use neuralbroker/blitzkode with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf neuralbroker/blitzkode # Run inference directly in the terminal: llama-cli -hf neuralbroker/blitzkode
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf neuralbroker/blitzkode # Run inference directly in the terminal: llama-cli -hf neuralbroker/blitzkode
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf neuralbroker/blitzkode # Run inference directly in the terminal: ./llama-cli -hf neuralbroker/blitzkode
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf neuralbroker/blitzkode # Run inference directly in the terminal: ./build/bin/llama-cli -hf neuralbroker/blitzkode
Use Docker
docker model run hf.co/neuralbroker/blitzkode
- LM Studio
- Jan
- vLLM
How to use neuralbroker/blitzkode with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "neuralbroker/blitzkode" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "neuralbroker/blitzkode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/neuralbroker/blitzkode
- Ollama
How to use neuralbroker/blitzkode with Ollama:
ollama run hf.co/neuralbroker/blitzkode
- Unsloth Studio new
How to use neuralbroker/blitzkode with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for neuralbroker/blitzkode to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for neuralbroker/blitzkode to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for neuralbroker/blitzkode to start chatting
- Pi new
How to use neuralbroker/blitzkode with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf neuralbroker/blitzkode
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "neuralbroker/blitzkode" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use neuralbroker/blitzkode with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf neuralbroker/blitzkode
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default neuralbroker/blitzkode
Run Hermes
hermes
- Docker Model Runner
How to use neuralbroker/blitzkode with Docker Model Runner:
docker model run hf.co/neuralbroker/blitzkode
- Lemonade
How to use neuralbroker/blitzkode with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull neuralbroker/blitzkode
Run and chat with the model
lemonade run user.blitzkode-{{QUANT_TAG}}List all available models
lemonade list
File size: 21,806 Bytes
ccde9ab | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | #!/usr/bin/env python3
"""Push a PEFT/LoRA adapter checkpoint to the Hugging Face Hub.
Usage examples
--------------
# Validate everything without pushing:
python scripts/push_to_hub.py --dry-run
# Push with defaults (reads HF_TOKEN from environment):
python scripts/push_to_hub.py
# Explicit options:
python scripts/push_to_hub.py \\
--checkpoint checkpoints/available-lora-0.5b-full/final \\
--repo-id neuralbroker/blitzkode-lora-0.5b \\
--commit-message "Add trained adapter v2.1"
# Private repo push with explicit token:
python scripts/push_to_hub.py --private --token hf_...
"""
from __future__ import annotations
import argparse
import json
import os
import sys
import textwrap
from pathlib import Path
# ---------------------------------------------------------------------------
# Constants / defaults
# ---------------------------------------------------------------------------
REPO_ROOT = Path(__file__).resolve().parents[1]
DEFAULT_CHECKPOINT = REPO_ROOT / "checkpoints" / "available-lora-0.5b-full" / "final"
DEFAULT_REPO_ID = "neuralbroker/blitzkode-lora-0.5b"
DEFAULT_REPO_TYPE = "model"
DEFAULT_COMMIT_MSG = "Upload BlitzKode LoRA adapter"
# Files that must be present for a valid PEFT adapter
REQUIRED_FILES = ["adapter_config.json", "adapter_model.safetensors"]
# ---------------------------------------------------------------------------
# CLI argument parsing
# ---------------------------------------------------------------------------
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--checkpoint",
type=Path,
default=DEFAULT_CHECKPOINT,
metavar="PATH",
help=(
f"Path to the adapter checkpoint directory. "
f"(default: {DEFAULT_CHECKPOINT})"
),
)
parser.add_argument(
"--repo-id",
default=DEFAULT_REPO_ID,
metavar="OWNER/REPO",
help=f"HuggingFace repo to push to. (default: {DEFAULT_REPO_ID})",
)
parser.add_argument(
"--repo-type",
default=DEFAULT_REPO_TYPE,
choices=("model", "dataset", "space"),
help=f"Repository type. (default: {DEFAULT_REPO_TYPE})",
)
parser.add_argument(
"--private",
action="store_true",
help="Create the repository as private. (default: public)",
)
parser.add_argument(
"--token",
default=None,
metavar="HF_TOKEN",
help=(
"HuggingFace API write token. "
"Falls back to the HF_TOKEN environment variable if not set."
),
)
parser.add_argument(
"--create-repo",
action=argparse.BooleanOptionalAction,
default=True,
help=(
"Create the HuggingFace repo if it does not exist. "
"Use --no-create-repo to skip. (default: True)"
),
)
parser.add_argument(
"--commit-message",
default=DEFAULT_COMMIT_MSG,
metavar="MSG",
help=f"Commit message for the Hub upload. (default: '{DEFAULT_COMMIT_MSG}')",
)
parser.add_argument(
"--dry-run",
action="store_true",
help=(
"Validate the checkpoint and configuration but do NOT push anything "
"to Hugging Face Hub. Useful for CI or pre-flight checks."
),
)
return parser.parse_args()
# ---------------------------------------------------------------------------
# Dependency check
# ---------------------------------------------------------------------------
def check_huggingface_hub() -> None:
"""Abort with a helpful message if huggingface_hub is not installed."""
try:
import huggingface_hub # noqa: F401 # type: ignore[import]
except ImportError:
print(
"\n[ERROR] The `huggingface_hub` package is not installed.\n"
"Install it with one of the following commands:\n\n"
" pip install huggingface_hub\n"
" pip install -r requirements-training.txt\n",
file=sys.stderr,
)
sys.exit(1)
# ---------------------------------------------------------------------------
# Checkpoint validation
# ---------------------------------------------------------------------------
def validate_checkpoint(checkpoint: Path) -> dict:
"""Ensure the checkpoint directory is valid.
Checks that the directory exists and contains every file listed in
REQUIRED_FILES. Returns the parsed ``adapter_config.json`` dict.
"""
if not checkpoint.exists():
print(
f"\n[ERROR] Checkpoint directory not found: {checkpoint}\n"
"Run training first, e.g.:\n"
" python scripts/train_available.py\n",
file=sys.stderr,
)
sys.exit(1)
if not checkpoint.is_dir():
print(
f"\n[ERROR] Checkpoint path is not a directory: {checkpoint}\n",
file=sys.stderr,
)
sys.exit(1)
missing = [f for f in REQUIRED_FILES if not (checkpoint / f).exists()]
if missing:
print(
f"\n[ERROR] Missing required files in {checkpoint}:\n"
+ "\n".join(f" - {f}" for f in missing)
+ "\n\nIs this a valid PEFT adapter checkpoint?\n",
file=sys.stderr,
)
sys.exit(1)
config_path = checkpoint / "adapter_config.json"
try:
adapter_config: dict = json.loads(config_path.read_text(encoding="utf-8"))
except json.JSONDecodeError as exc:
print(
f"\n[ERROR] adapter_config.json is not valid JSON: {exc}\n",
file=sys.stderr,
)
sys.exit(1)
except OSError as exc:
print(
f"\n[ERROR] Could not read adapter_config.json: {exc}\n",
file=sys.stderr,
)
sys.exit(1)
return adapter_config
# ---------------------------------------------------------------------------
# Token resolution
# ---------------------------------------------------------------------------
def resolve_token(args_token: str | None, *, dry_run: bool = False) -> str:
"""Return the HF token, or abort with instructions if none is found."""
token = args_token or os.environ.get("HF_TOKEN", "")
if token:
return token
if dry_run:
# A token is not needed for dry runs, return a placeholder.
return "__dry_run_placeholder__"
print(
"\n[ERROR] No HuggingFace API token found.\n"
"Provide a write token using one of these methods:\n\n"
" 1. CLI flag:\n"
" python scripts/push_to_hub.py --token hf_YOUR_TOKEN\n\n"
" 2. Environment variable (recommended):\n"
" Windows CMD : set HF_TOKEN=hf_YOUR_TOKEN\n"
" PowerShell : $env:HF_TOKEN = 'hf_YOUR_TOKEN'\n"
" Linux/macOS : export HF_TOKEN=hf_YOUR_TOKEN\n\n"
" 3. HuggingFace CLI login (persists across sessions):\n"
" pip install huggingface_hub\n"
" huggingface-cli login\n\n"
"Generate a token at: https://huggingface.co/settings/tokens\n"
"Make sure the token has **write** access to the target repo.\n",
file=sys.stderr,
)
sys.exit(1)
# ---------------------------------------------------------------------------
# Model card / README generation
# ---------------------------------------------------------------------------
def build_model_card(adapter_config: dict, repo_id: str) -> str:
"""Generate the HuggingFace-compatible README.md content for the adapter repo."""
base_model = adapter_config.get(
"base_model_name_or_path", "Qwen/Qwen2.5-0.5B-Instruct"
)
lora_r = adapter_config.get("r", 16)
lora_alpha = adapter_config.get("lora_alpha", 32)
lora_dropout = adapter_config.get("lora_dropout", 0.05)
target_modules: list = adapter_config.get("target_modules", [])
modules_str = (
", ".join(f"`{m}`" for m in target_modules)
if target_modules
else "`q_proj`, `k_proj`, `v_proj`, `o_proj`"
)
# YAML frontmatter -------------------------------------------------------
frontmatter = textwrap.dedent(f"""\
---
language:
- en
license: mit
library_name: peft
tags:
- code-generation
- lora
- qwen2.5
- blitzkode
- coding-assistant
- fine-tuned
- peft
base_model: {base_model}
pipeline_tag: text-generation
---
""")
# README body ------------------------------------------------------------
body = textwrap.dedent(f"""\
# BlitzKode LoRA Adapter (0.5B)
**BlitzKode** is a local AI coding assistant fine-tuned from
**[{base_model}](https://huggingface.co/{base_model})** using LoRA
(Low-Rank Adaptation). This repository contains the PEFT adapter β the
research-friendly version that can be hot-loaded on top of the base model.
> **Creator:** [Sajad (neuralbroker)](https://github.com/neuralbroker)
> **GitHub:** <https://github.com/neuralbroker/blitzkode>
> **Production GGUF:** [`neuralbroker/blitzkode`](https://huggingface.co/neuralbroker/blitzkode)
---
## Model Details
| Property | Value |
|---|---|
| **Adapter version** | 2.1 |
| **Base model** | `{base_model}` |
| **LoRA rank (r)** | {lora_r} |
| **LoRA alpha** | {lora_alpha} |
| **LoRA dropout** | {lora_dropout} |
| **Target modules** | {modules_str} |
| **Training steps** | 50 |
| **Final loss** | ~0.48 |
| **Library** | PEFT |
| **License** | MIT |
---
## Training Pipeline
This adapter was produced by a **4-stage fine-tuning pipeline** applied
to the Qwen2.5 family:
| Stage | Method | Purpose |
|---|---|---|
| 1 | SFT | Supervised fine-tuning on 71 curated algorithmic coding problems |
| 2 | Reward-SFT | Continued SFT with heuristic reward signals for code correctness and formatting |
| 3 | DPO | Direct Preference Optimization on handcrafted chosen/rejected pairs |
| 4 | LoRA SFT (this adapter) | Final LoRA fine-tune (r={lora_r}) on 99 samples; base model Qwen2.5-0.5B |
### Training Dataset (199 total samples)
| Subset | Count | Source | License |
|---|---|---|---|
| Curated algorithmic problems | 71 | Custom (local) β arrays, strings, trees, DP, graphs | MIT |
| MetaMathQA samples | 100 | [`meta-math/MetaMathQA`](https://huggingface.co/datasets/meta-math/MetaMathQA) | CC BY 4.0 |
| Python/JavaScript patterns | 28 | Custom (local) β decorators, context managers, data classes | MIT |
| **Total** | **199** | | |
---
## Usage
### Load with PEFT
```python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base_model_id = "{base_model}"
adapter_repo = "{repo_id}"
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype="auto",
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, adapter_repo)
model.eval()
```
### Generate code
```python
prompt = (
"<|im_start|>system\\n"
"You are BlitzKode, a precise AI coding assistant created by Sajad.\\n"
"<|im_end|>\\n"
"<|im_start|>user\\n"
"Write a Python function for binary search with full edge-case handling.\\n"
"<|im_end|>\\n"
"<|im_start|>assistant\\n"
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=300,
temperature=0.7,
do_sample=True,
repetition_penalty=1.1,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
### Merge adapter into base model (for export)
```python
merged = model.merge_and_unload()
merged.save_pretrained("blitzkode-0.5b-merged")
tokenizer.save_pretrained("blitzkode-0.5b-merged")
```
---
## Prompt Format
BlitzKode uses the **ChatML** template standard for Qwen models:
```
<|im_start|>system
You are BlitzKode, a precise AI coding assistant created by Sajad.<|im_end|>
<|im_start|>user
{{your question}}<|im_end|>
<|im_start|>assistant
```
---
## Limitations
- **Text-only** β no image/multimodal support.
- **0.5B parameters** β smaller and faster than the 1.5B GGUF variant; may be
less accurate on complex algorithmic tasks.
- **2048-token context** β not suitable for long repository-level analysis.
- **Review all outputs** β generated code must be tested before use in production.
- **Not security-audited** β do not use for cryptographic or safety-critical code
without thorough expert review.
- **Math reasoning** β MetaMathQA training improves basic reasoning but does not
substitute a dedicated math model.
---
## Relation to the Production Model
| Variant | Repo | Size | Runtime | Use case |
|---|---|---|---|---|
| GGUF (1.5B, F16) | [`neuralbroker/blitzkode`](https://huggingface.co/neuralbroker/blitzkode) | ~3 GB | llama.cpp / llama-cpp-python | Production; CPU/GPU, no Python ML stack needed |
| LoRA adapter (0.5B) | `{repo_id}` (this repo) | ~100 MB | PEFT + Transformers | Research; merging, further fine-tuning, quantization |
---
## License
**MIT** β see [LICENSE](https://github.com/neuralbroker/blitzkode/blob/main/LICENSE).
You must also comply with the upstream
[{base_model}](https://huggingface.co/{base_model}) license
when redistributing any derived weights.
---
## Citation
```bibtex
@software{{blitzkode2025,
author = {{Sajad}},
title = {{BlitzKode: A Local AI Coding Assistant}},
year = {{2025}},
url = {{https://github.com/neuralbroker/blitzkode}}
}}
```
""")
return frontmatter + "\n" + body
# ---------------------------------------------------------------------------
# Main push routine
# ---------------------------------------------------------------------------
def push(args: argparse.Namespace) -> None: # noqa: C901
check_huggingface_hub()
# Import here so the check above can give a clean error first.
from huggingface_hub import HfApi # type: ignore[import]
from huggingface_hub.utils import HfHubHTTPError # type: ignore[import]
sep = "=" * 70
print(sep)
print("BlitzKode β Push LoRA Adapter to Hugging Face Hub")
if args.dry_run:
print("(DRY RUN β nothing will be pushed)")
print(sep)
# ------------------------------------------------------------------
# Step 1: Validate checkpoint
# ------------------------------------------------------------------
print(f"\n[1/5] Validating checkpoint directory β¦")
print(f" Path: {args.checkpoint}")
adapter_config = validate_checkpoint(args.checkpoint)
base_model = adapter_config.get("base_model_name_or_path", "unknown")
lora_r = adapter_config.get("r", "?")
lora_alpha = adapter_config.get("lora_alpha", "?")
target_modules = adapter_config.get("target_modules", [])
files_found = sorted(p.name for p in args.checkpoint.iterdir() if p.is_file())
print(f" base_model : {base_model}")
print(f" lora r / alpha : {lora_r} / {lora_alpha}")
print(f" target_modules : {target_modules}")
print(f" files : {files_found}")
print(" [OK] Checkpoint is valid.")
# ------------------------------------------------------------------
# Step 2: Resolve token
# ------------------------------------------------------------------
print("\n[2/5] Resolving HuggingFace token β¦")
token = resolve_token(args.token, dry_run=args.dry_run)
if args.dry_run:
print(" [OK] Token check skipped (dry run).")
else:
masked = token[:8] + "..." if len(token) > 8 else "***"
print(f" [OK] Token resolved (starts with: {masked})")
# ------------------------------------------------------------------
# Dry-run exit
# ------------------------------------------------------------------
if args.dry_run:
print()
print(sep)
print("DRY RUN COMPLETE β all validations passed, nothing was pushed.")
print(f" Checkpoint : {args.checkpoint}")
print(f" Target repo : https://huggingface.co/{args.repo_id}")
print(f" Repo type : {args.repo_type}")
print(f" Private : {args.private}")
print(f" Files ready : {files_found}")
print(sep)
return
api = HfApi(token=token)
# ------------------------------------------------------------------
# Step 3: Create repo (if requested)
# ------------------------------------------------------------------
if args.create_repo:
print(f"\n[3/5] Creating / verifying repo: {args.repo_id} β¦")
try:
repo_url = api.create_repo(
repo_id=args.repo_id,
repo_type=args.repo_type,
private=args.private,
exist_ok=True, # silently succeed if repo already exists
)
print(f" [OK] Repo ready: {repo_url}")
except HfHubHTTPError as exc:
print(
f"\n[ERROR] Failed to create / access repo '{args.repo_id}':\n"
f" {exc}\n"
"Check that your token has write access and the repo name is correct.\n",
file=sys.stderr,
)
sys.exit(1)
else:
print("\n[3/5] Skipping repo creation (--no-create-repo).")
# ------------------------------------------------------------------
# Step 4: Upload checkpoint folder
# ------------------------------------------------------------------
print(f"\n[4/5] Uploading checkpoint folder β {args.repo_id} β¦")
print(f" Commit message: \"{args.commit_message}\"")
try:
commit_info = api.upload_folder(
folder_path=str(args.checkpoint),
repo_id=args.repo_id,
repo_type=args.repo_type,
commit_message=args.commit_message,
)
commit_ref = getattr(commit_info, "oid", None) or str(commit_info)
print(f" [OK] Folder uploaded. Commit: {commit_ref}")
except HfHubHTTPError as exc:
print(
f"\n[ERROR] Folder upload failed:\n {exc}\n",
file=sys.stderr,
)
sys.exit(1)
# ------------------------------------------------------------------
# Step 5: Upload model card README.md
# ------------------------------------------------------------------
print("\n[5/5] Uploading model card (README.md) β¦")
readme_content = build_model_card(adapter_config, args.repo_id)
try:
api.upload_file(
path_or_fileobj=readme_content.encode("utf-8"),
path_in_repo="README.md",
repo_id=args.repo_id,
repo_type=args.repo_type,
commit_message="Update model card README.md",
)
print(" [OK] README.md uploaded.")
except HfHubHTTPError as exc:
# Non-fatal: the adapter files are already uploaded.
print(
f"\n[WARN] Could not upload README.md (adapter files were uploaded OK):\n"
f" {exc}\n"
"You can upload the model card manually from the Hub web interface.\n",
file=sys.stderr,
)
# ------------------------------------------------------------------
# Summary
# ------------------------------------------------------------------
repo_url = f"https://huggingface.co/{args.repo_id}"
print()
print(sep)
print("PUSH COMPLETE")
print(f" Repo URL : {repo_url}")
print(f" Checkpoint : {args.checkpoint}")
print(f" Files pushed : {files_found}")
print(f" Base model : {base_model}")
print(f" LoRA r/alpha : {lora_r}/{lora_alpha}")
print(f" Commit msg : {args.commit_message}")
print(sep)
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
def main() -> None:
args = parse_args()
push(args)
if __name__ == "__main__":
main()
|