Instructions to use sarathi-balakrishnan/llama-agri-b2b-intelligence with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sarathi-balakrishnan/llama-agri-b2b-intelligence with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-Instruct") model = PeftModel.from_pretrained(base_model, "sarathi-balakrishnan/llama-agri-b2b-intelligence") - Notebooks
- Google Colab
- Kaggle
Llama 3.1 8B β Agricultural B2B Intelligence (LoRA adapter, experiment)
Built with Llama.
Personal experiment (December 2025). This LoRA adapter for Llama-3.1-8B-Instruct was trained on 10,000 agricultural business-analysis answers produced by two commercial LLMs. It is a study of sequence-level knowledge distillation: supervised fine-tuning on teacher outputs. So far it has been evaluated only by training and validation loss. No task benchmark has been run yet.
Merged-weights version: llama-agri-b2b-intelligence-merged
Summary
| Base model | meta-llama/Llama-3.1-8B-Instruct (8.03B) |
| Method | LoRA SFT on teacher-generated responses (sequence-level distillation) |
| Teacher outputs | 5,007 from Claude Sonnet 4, 4,993 from GPT-4.1 (10,000 total, ~1,150 tokens avg) |
| Split | 8,500 train / 1,000 validation / 500 test (test set not yet used) |
| LoRA | r = 128, Ξ± = 256, dropout 0.05, all 7 projections in every layer |
| Trainable parameters | 335,544,320 (β4.18% of 8.03B) |
| Adapter file | 1.34 GB (adapter_model.safetensors, FP32) |
| Hardware / time | 1Γ NVIDIA DGX Spark (GB10), ~55 h for 3 epochs (798 steps, ~4 min/step, ~45 GB memory) |
| Evaluation | Loss only. Benchmark pending |
How the data was made
- I built a knowledge base and a query generator for US agricultural regions and B2B sectors (crop insurance, equipment, seed, fertilizer, crop protection, irrigation, lending, land brokerage).
- I generated 10,000 queries. The mix: county 30%, zip code 15%, market 10%, state 10%, risk 8%, B2B marketing 8%, predictions 6%, historical trends 6%, commodity 4%, comparative 3%.
- Each query was sent once to one teacher through the providers' APIs. That gave 5,007 Claude Sonnet 4
responses (
$100 of API usage) and 4,993 GPT-4.1 responses ($80). - The student was fine-tuned with standard next-token cross-entropy on those responses. No teacher logits were used (they aren't available from these APIs), so this is sequence-level KD, not logit/KL distillation.
About the teacher data. The training targets are outputs from third-party models. Anyone using this adapter or its data is also subject to the terms of the providers whose models generated those outputs (Anthropic and OpenAI), in addition to the Llama 3.1 Community License. Please review those terms for your use case. The responses weren't fact-checked, so any statistics they contain may be wrong.
Training metrics
| Metric | Epoch 1 | Epoch 2 | Epoch 3 |
|---|---|---|---|
| Training loss | 0.89 | 0.77 | ~0.70 |
| Validation loss | 0.87 | 0.82 | ~0.78 |
| Cumulative steps | 266 | 532 | 798 |
| Wall-clock | 18.5 h | 18.5 h | 18 h |
| Learning rate (cosine) | 5e-5 β 4.1e-5 | 4.1e-5 β 1.6e-5 | 1.6e-5 β 0 |
By epoch 3, training loss (0.70) and validation loss (0.78) are starting to separate. A 4th epoch would
probably overfit.
LORA_CONFIG = dict(r=128, lora_alpha=256, lora_dropout=0.05, bias="none", task_type="CAUSAL_LM",
target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"])
TRAINING_CONFIG = dict(num_train_epochs=3, per_device_train_batch_size=2,
gradient_accumulation_steps=16, # effective batch 32
learning_rate=5e-5, warmup_ratio=0.1, lr_scheduler_type="cosine",
bf16=True, gradient_checkpointing=True, max_seq_length=4096)
Parameter count check. Each layer adds rΒ·(d_in + d_out) parameters per projection. For Llama-3.1-8B (hidden 4096, KV dim 1024, MLP 14336) at r = 128 that gives 10,485,760 per layer. Across 32 layers that is 335,544,320. An earlier version of this card said 167,772,160 (2.09%), which is the r = 64 figure. The FP32 adapter file size (1,342,238,560 bytes β 335.5M Γ 4 bytes) confirms the corrected number.
What's missing / lessons learned
- Loss isn't quality. Lower validation loss shows the student imitates the teachers' style. It doesn't show the answers are correct or useful. The planned evaluation is to run the 500-example test split through base Llama-3.1-8B-Instruct, this adapter, and both teachers, then score with an LLM judge using a fixed rubric (factuality, structure, actionability) plus a human spot check.
- Rank 128 was probably more than needed. Lower ranks (16β64) are common for style and format adaptation. A rank sweep would show whether the 1.34 GB adapter could be much smaller.
- I didn't track which teacher the student follows. A per-teacher validation loss would show whether mixing two teachers helps or just averages their styles.
- Throughput. About 4 minutes per optimizer step (32 sequences Γ up to 4,096 tokens) on a single GB10. Sequence packing and a smaller rank would cut the 55 h substantially.
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
base_model_name = "meta-llama/Llama-3.1-8B-Instruct"
adapter_name = "sarathi-balakrishnan/llama-agri-b2b-intelligence"
tokenizer = AutoTokenizer.from_pretrained(base_model_name)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name, torch_dtype=torch.bfloat16, device_map="auto"
)
model = PeftModel.from_pretrained(base_model, adapter_name)
messages = [
{"role": "system", "content": "You are an agricultural business intelligence analyst."},
{"role": "user", "content": "Analyze Iowa's corn market for a seed company evaluating expansion."},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=1500, temperature=0.7, top_p=0.9,
repetition_penalty=1.1, do_sample=True)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Optional merge:
merged = model.merge_and_unload()
merged.save_pretrained("./llama-agri-merged")
tokenizer.save_pretrained("./llama-agri-merged")
Output format the model was trained to follow
Executive Summary β Geographic/Market Profile β Analysis β Opportunities β Risk Factors β Recommendations β Confidence Level β Data Sources.
Limitations
- Not benchmarked. See above.
- Synthetic, unverified targets. The responses were written by LLMs and not checked by domain experts. Figures such as acreage, market sizes, and percentages can be invented. Verify them against USDA NASS/ERS or other primary sources.
- US agriculture only. English only. Trained on 4,096-token sequences.
- Not for regulatory, lending, insurance, investment, or trading decisions.
Files
adapter_config.json, adapter_model.safetensors (1.34 GB), tokenizer files.
License
This adapter is a Llama 3.1 derivative. It is distributed under the Llama 3.1 Community License, and use must also comply with Meta's Acceptable Use Policy. Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright Β© Meta Platforms, Inc. All Rights Reserved. See also the note on teacher-generated data above.
Citation
@misc{llama-agri-b2b-intelligence-2025,
title = {Llama 3.1 8B Agricultural B2B Intelligence: a sequence-level distillation experiment},
author = {Sarathi Balakrishnan},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/sarathi-balakrishnan/llama-agri-b2b-intelligence}
}
- Downloads last month
- 35
Model tree for sarathi-balakrishnan/llama-agri-b2b-intelligence
Base model
meta-llama/Llama-3.1-8B