Fhenix AI Assistant โ€” Llama 3.1 8B LoRA

A fine-tuned version of Meta Llama 3.1 8B Instruct specialized in Fhenix blockchain development and Fully Homomorphic Encryption (FHE) smart contracts.

Model Details

Property Value
Base model meta-llama/Llama-3.1-8B-Instruct
Fine-tuning method LoRA (PEFT)
Quantization 4-bit (NF4)
Trainable parameters 41.9M / 8.07B (0.52%)
Training epochs 3
Final train loss 1.07 โ†’ 0.52
Final eval loss 0.601
Training time ~30 minutes on RTX 5060 Ti

Training Data

  • 335 curated Fhenix Q&A pairs (268 train / 33 val / 34 test)
  • Topics: FHE.sol operations, @cofhe/sdk, encrypted types, Hardhat testing, frontend integration, access control, permits, gas optimization

Capabilities

  • FHE.sol arithmetic, comparison, bitwise, and conditional operations
  • Encrypted types: ebool, euint8/16/32/64/128, eaddress
  • @cofhe/sdk client library โ€” encryption, decryption, permits
  • Smart contract development with encrypted storage
  • Hardhat testing and deployment for FHE contracts
  • Frontend integration with React/Next.js
  • Debugging and troubleshooting FHE applications
  • Gas optimization techniques specific to FHE

Usage

from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch

# Load base model in 4-bit
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.float16,
)
base_model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.1-8B-Instruct",
    quantization_config=bnb_config,
    device_map="auto"
)

# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "shree291/fhenix-llama3-lora")
tokenizer = AutoTokenizer.from_pretrained("shree291/fhenix-llama3-lora")
model.eval()

# Ask a question
messages = [
    {"role": "system", "content": "You are an expert Fhenix blockchain developer assistant specializing in Fully Homomorphic Encryption (FHE) smart contracts."},
    {"role": "user", "content": "How do I encrypt a uint32 value in a Solidity contract?"}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=300, temperature=0.7, do_sample=True)

answer = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(answer)

Example Outputs

Q: What is FHE.select and when should I use it?

FHE.select is a conditional operator that selects between two encrypted values based on an encrypted boolean condition โ€” the FHE equivalent of an if-else statement. Use it when you need conditional logic without revealing the condition. Example: euint32 result = FHE.select(isGreater, a, b);

Q: What is the role of the Threshold Network in Fhenix?

The Threshold Network provides decentralized threshold decryption. Multiple independent nodes collectively decrypt values using threshold cryptography โ€” no single node can decrypt alone. It validates permits and ACL permissions before decrypting, secured via EigenLayer staking.

LoRA Configuration

{
  "r": 16,
  "lora_alpha": 32,
  "target_modules": ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
  "lora_dropout": 0.05,
  "bias": "none",
  "task_type": "CAUSAL_LM"
}

Limitations

  • Specialized for Fhenix/CoFHE โ€” not a general-purpose coding assistant
  • Based on Llama 3.1 license terms โ€” requires accepting Meta's license
  • Small dataset (335 pairs) โ€” may hallucinate on edge cases not covered in training

License

This adapter follows the Llama 3.1 Community License.

Downloads last month
10
Safetensors
Model size
8B params
Tensor type
F16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for shree291/fhenix-llama3-lora

Adapter
(3,113)
this model