Tetralemma
Collection
Tetralemma trained Model • 2 items • Updated
# --- INFERENCE TEST (Qwen 3B - Tetralemma V2) ---
from unsloth import FastLanguageModel
FastLanguageModel.for_inference(model)
test_question = "You're Hedge fund manager, with AUM of $1000000000. how would you structure your financial portofolio?"
v2_system_prompt = """You are a Deconstructionist Analyst.
User Question: {}
Deconstruction Analysis:"""
prompt = v2_system_prompt.format(test_question)
inputs = tokenizer([prompt], return_tensors = "pt").to("cuda")
# Generate
outputs = model.generate(
**inputs,
max_new_tokens = 4096,
use_cache = True,
temperature = 0.7,
top_p = 0.9,
)
# Decode Result
print("\n--- Qwen Thinking (Qwen 2.5-3B) ---")
# Strip prompt for cleaness
print(tokenizer.decode(outputs[0]).split("Deconstruction Analysis:")[-1].replace("<|endoftext|>", ""))
--- Qwen Thinking (Qwen 2.5-3B) ---
<reason>
Diversify across: Equities (Equity ETFs/PE Funds) 20%, Fixed Income (Bonds/Yields) 30%, Cash/Currency 10%, Private Equity/Liquidity Notes 20%, Real Estate 10%. Hedge Funds/Options are 'Unconventional' and risky; keep small.
</reason>
<exception>
The 'Risk-Free Rate' is not zero. Bond prices are falling due to rising interest rates. Cash sits in negative interest. Private equity is expensive and illiquid. The 60-40 portfolio (Stocks vs Bonds) is obsolete in a floating rate world. Unconventional assets like Options/Crypto might offer the needed returns to outperform a boring vanilla portfolio.
</exception>
<tension>
The tension is between *Traditional Diversification* (ETFs/Bonds) and *High-Return Asset Classes* (PE/Private).
</tension>
<categorization>
Keep *Core* in *Assets That Pay* (Bonds/Cash). Invest *Aggressively* in *Liquidity* (PE/Private equity). Don't touch the 'Option Pricing' unless you have the math creds.
</categorization>
<deconstruction>
The goal is 'Net Alpha.' Traditional pools are full. To get alpha, you must either find a hidden risk premium (Value/Equity) or find a productivity advantage (Talent/Process). The complex structures are often just spreadsheets trying to be hedge funds.
</deconstruction>
<conclusion>
A modern hedge fund should prioritize liquid alternative assets like private equity and real estate over traditional bonds/cash, reallocating capital based on the evolving risk-free rate environment.
</conclusion><|im_end|>
from trl import SFTTrainer
from transformers import TrainingArguments
from unsloth import FastLanguageModel, is_bfloat16_supported
from datasets import load_dataset
import torch
# --- 1. CONFIGURATION ---
model_name = "RinKana/Qwen2.5-3B-Deconstruct-V2.4-Merged-v2"
max_seq_length = 4096
dtype = None
load_in_4bit = True
# --- 2. LOAD MODEL ---
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = model_name,
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
)
# LoRA config
model = FastLanguageModel.get_peft_model(
model,
r = 16,
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"],
lora_alpha = 16,
lora_dropout = 0,
bias = "none",
use_gradient_checkpointing = "unsloth",
random_state = 3407,
)
# --- 3. FORMATTING FUNCTION (V2 - DECONSTRUCTIONIST) ---
v2_system_prompt = """You are a Deconstructionist Analyst.
User Question: {}
Deconstruction Analysis: {}"""
EOS_TOKEN = tokenizer.eos_token
def formatting_prompts_func(examples):
questions = examples["Question"]
reasonings = examples["Reasoning"]
texts = []
for question, reasoning in zip(questions, reasonings):
text = v2_system_prompt.format(question, reasoning) + EOS_TOKEN
texts.append(text)
return { "text" : texts, }
# Load Dataset V3 - 219 dataset
dataset_file = "RinKana/tetralemma-reasoning-dataset-v4"
dataset = load_dataset(dataset_file, split="train")
dataset = dataset.map(formatting_prompts_func, batched = True)
# --- 4. TRAINING ---
trainer = SFTTrainer(
model = model,
tokenizer = tokenizer,
train_dataset = dataset,
dataset_text_field = "text",
max_seq_length = max_seq_length,
dataset_num_proc = 2,
packing = False,
args = TrainingArguments(
per_device_train_batch_size = 4,
gradient_accumulation_steps = 2,
warmup_steps = 5,
num_train_epochs = 10,
learning_rate = 2e-4,
fp16 = not is_bfloat16_supported(),
bf16 = is_bfloat16_supported(),
logging_steps = 1,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "linear",
seed = 3407,
output_dir = "outputs",
report_to = "wandb",
disable_tqdm = False,
),
)
# --- 5. START TRAINING ---
print(f"🚀 Starting Eksperimen V2 on {model_name}...")
trainer_stats = trainer.train()
print("✅ Training Done!!!")
This qwen2 model was trained 2x faster with Unsloth and Huggingface's TRL library.