Skip to main content

Shard

Make your own character LLM.

A Python package for fine-tuning large language models to behave like specific characters using LoRA.

Installation

  1. Install it with pip:
pip install shard-llm

Features

  • Fine-tune LLMs to mimic specific characters
  • Parameter-efficient training with LoRA
  • Support for 4-bit and 8-bit quantization
  • Easy conversion to Ollama-compatible formats
  • Simple API for dataset creation and response generation

Quick Start

from shard_ai import CharacterTuner, ResponseGenerator

# Initialize the tuner
tuner = CharacterTuner(
    model_name="meta-llama/Llama-3.1-8B-Instruct",
    output_dir="./sherlock-llama-lora"
)

# Create a character dataset
examples = [
    {
        "user": "What do you think about this case?",
        "assistant": "The facts, as presented, suggest a crime of passion rather than premeditation. Elementary deduction, really."
    },
    {
        "user": "Can you help me find my missing watch?",
        "assistant": "Observe the slight indentation on your right wrist, indicating you've worn the watch consistently until very recently. Have you checked the pocket of the jacket you wore during yesterday's garden excursion?"
    }
]

dataset_path = tuner.create_character_dataset(
    character_name="Sherlock Holmes",
    character_description="is a brilliant detective with exceptional deductive reasoning skills. You speak in a formal, precise manner, often making keen observations about details others miss.",
    examples=examples,
    output_file="sherlock_dataset.jsonl"
)

# Fine-tune the model
model, tokenizer = tuner.fine_tune(
    dataset_path=dataset_path,
    batch_size=2,
    num_epochs=3
)

# Generate responses with the fine-tuned model
generator = ResponseGenerator("./sherlock-llama-lora")
# Integrated generator for testing
response = generator.generate_response("Tell me about a case you solved recently")
print(response)

Converting to Ollama

from shard_ai import ModelConverter

# Merge LoRA weights with base model
merged_model_path = ModelConverter.merge_lora_weights(
    base_model_name="meta-llama/Llama-3.1-8B-Instruct",
    lora_model_path="./sherlock-llama-lora",
    output_dir="./sherlock-llama-merged"
)

# Create Ollama modelfile
modelfile_path = ModelConverter.create_ollama_modelfile(
    model_path=merged_model_path,
    model_name="sherlock-llama",
    system_prompt="You are Sherlock Holmes, a brilliant detective with exceptional deductive reasoning skills."
)

# Optional: Convert to GGUF format
gguf_path = ModelConverter.convert_to_gguf(
    model_path=merged_model_path,
    output_path="./sherlock-llama.gguf",
    quantization="f16"
)

Metadata

Release files for shard-llm 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shard-llm 1.0.6
File Size Uploaded Provenance Actions
shard_llm-1.0.6.tar.gz 169.3 kB Without provenance Details for shard_llm-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shard-llm 1.0.6
File Interpreter ABI Platform Actions
shard_llm-1.0.6-py3-none-any.whl Python 3 none any Details for shard_llm-1.0.6-py3-none-any.whl

Total release size: 339.5 kB

Release files / shard_llm-1.0.6.tar.gz

Download URL shard_llm-1.0.6.tar.gz
Size 169.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c1ad092c2eef89903e376a611c2a4d09154b18daf04b3895b84fc9e77485b05b
BLAKE2b-256 checksum
How to use checksums
d6ceeb982fa6e4802c6cbdf815229bfb2cca89f541670f20f59b88e51303aea0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Windows/10

Release files / shard_llm-1.0.6-py3-none-any.whl

Download URL shard_llm-1.0.6-py3-none-any.whl
Size 170.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec958a9f250e2c1ba71ee459373a5e8d00d5471c3b99dcecd81b2f5be80fac1b
BLAKE2b-256 checksum
How to use checksums
612c138d84e121db61bea923cb867031660137455ec63c7c01111bbe91852f61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Windows/10

Security for shard-llm 1.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page