🔷
Locentra OS
🔷
Locentra OS
  • 🧠 Introduction
  • ⚙️ Features
  • 🛠 Under The Hood
  • 🧩 Installation
  • 🚀 Usage
  • 🧮 CLI Commands
  • 🔌 API Reference
  • 🤖 Agents System
  • 🧠 Semantic Memory
  • 🎓 Training & Fine-Tuning
  • 🔐 $LOCENTRA Token Access
  • 🏗 System Architecture
  • 🧩 Extending the System
  • 🧪 Testing & Quality Assurance
  • 📄 License & Open Source
Powered by GitBook
On this page

🎓 Training & Fine-Tuning

“We needed a way to teach the model something new—right now, on our terms, using our own data. Locentra lets us do exactly that.” — DevOps lead at a Web3 startup


Forget retraining offline or waiting for fine-tuning APIs. Locentra lets you push new knowledge into your model instantly, using a command-line call, a memory entry, or a triggered agent.

You own the loop.


🧪 Use Case: Feedback-Driven Adaptation

Let’s say your model keeps answering:

"LSTs are liquidity staking tools used in DeFi..."

But your team wants:

"LSTs are Liquid Staking Tokens that allow users to stake assets and retain liquidity."

You run:

python cli/train.py \
  --prompt "What are LSTs in DeFi?" \
  --completion "LSTs are Liquid Staking Tokens that allow users to..."

And just like that, Locentra adapts.

No checkpointing. No cloud calls. Just immediate domain alignment.


⚙️ How the Trainer Works

All fine-tuning logic lives in:

bashCopyEditbackend/models/trainer.py

It pulls from:

  • core/config.py → Training args

  • data/dataset.py → Prompt→Completion structuring

  • models/adapter.py → Base model + wrapping

  • cleaner.py → Full text sanitization

  • HuggingFace Trainer → Actual execution engine

Training runs in-memory and supports:

  • 🔁 Streaming datasets

  • 🧪 Dry-runs

  • 🧠 Semantic memory sync

  • ⏱ Fine-tuning on prompt impact delay


🧰 Configuration (Hybrid Model)

Training is controlled via both .env and code-based config:

.env Example

MODEL_NAME=tiiuae/falcon-rw-1b
TRAINING_EPOCHS=3
TRAINING_BATCH_SIZE=8
LEARNING_RATE=5e-5
TRAIN_ON_CPU=false

core/config.py

TRAINING_ARGS = {
    "per_device_train_batch_size": 8,
    "num_train_epochs": 3,
    "learning_rate": 5e-5,
    "logging_steps": 10,
    "save_steps": 0,
    "report_to": "none",
}

You can hot-swap models, epochs, or device targets without changing code.


🧠 Adapter Layer: Multi-LLM Ready

The file:

backend/models/adapter.py

wraps any HuggingFace model to support both inference and training pipelines.

It lets you:

  • Load Falcon, GPT-J, Mistral, LLaMA...

  • Inject quantization or LoRA (planned)

  • Switch models via env var only:

    MODEL_NAME=tiiuae/falcon-rw-1b

Restart the container — your OS now speaks a different LLM.


🧬 Advanced: Dataset Injection

Want to build long-term learning loops? Use:

backend/data/dataset.py

This utility:

  • Combines raw prompts + completions

  • Validates and tags entries

  • Optionally scores or vectorizes

  • Prepares HuggingFace Dataset objects

Supports:

  • Live session logs

  • Memory recall entries

  • User feedback strings

  • External dataset injections

Train from production logs. Or a Notion page. Or Slack dumps.


💥 Tips for Efficient Live Tuning

Strategy
Why It Works

--dry-run

Validate pipeline before consuming data

--vectorize

Sync training with memory recall

Small batch_size, epoch=1

Fast adaptation, even on CPU

Docker volume mount

Persist training logs & outputs

Schedule via cron or webhook

Automate daily/weekly LLM refresh


📂 Example: Bulk Train from File

Your file: prompts.jsonl

{ "prompt": "Define MEV", "completion": "MEV is..." }
{ "prompt": "zk-SNARK vs zk-STARK", "completion": "zk-SNARKs..." }

Run:

cat prompts.jsonl | while read line; do
  prompt=$(jq -r '.prompt' <<< $line)
  completion=$(jq -r '.completion' <<< $line)
  python cli/train.py --prompt "$prompt" --completion "$completion"
done

This is how you scale personal LLMs. Not with UI panels—through dev loops.

Previous🧠 Semantic MemoryNext🔐 $LOCENTRA Token Access

Last updated 1 day ago

Page cover image