โ PyTorch >= 2.0
โ
torch.backends.cuda.sdp_kernel
available
4. Standard
โ Always available (fallback terakhir)
๐๏ธ Force Specific Backend
# Force disable Flash Attention
config = CacaConfig(use_flash_attn=False)
model = CacaForCausalLM(config)
# Model akan skip Flash dan langsung ke xFormers/SDPA
# Check backend yang digunakan
import logging
logging.basicConfig(level=logging.INFO)
# Model akan log backend selection saat pertama kali digunakan
dummy_input = torch.randint(0, 1000, (1, 10)).cuda()
_ = model(dummy_input)
# Log: "โ Using Flash Attention backend" atau fallback
๐ Backend Compatibility
Backend
CUDA
CPU
MPS (Mac)
Dtype
Attention Mask
Sliding Window
Flash Attention
โ
โ
โ
FP16/BF16
โ (None only)
โ Native
xFormers
โ
โ
โ ๏ธ Limited
All
โ (None only)
โ Via mask
SDPA
โ
โ
โ
All
โ
โ Via mask
Standard
โ
โ
โ
All
โ
โ Via mask
๐ง Troubleshooting Backend Issues
# Flash Attention gagal dengan error CUDA
# Model akan otomatis fallback dan log warning:
# "โ ๏ธ Flash Attention gagal: <error>, fallback ke backend lain"
# Untuk debug, set logging level:
import logging
logging.basicConfig(level=logging.INFO)
# Model akan log:
# "โ Using Flash Attention backend"
# atau
# "โ ๏ธ Fallback to xFormers backend"
# atau
# "โน๏ธ Using SDPA backend"
# atau
# "โน๏ธ Using Standard attention backend"
# Start training
print("๐ Starting training...")
trainer.train()
# Save final model
print("๐พ Saving final model...")
trainer.save_model("./caca-indo-caca-250m-final")
tokenizer.save_pretrained("./caca-indo-caca-250m-final")
print("โ Training complete!")
๐ 5. Monitor Training
Dengan Weights & Biases
# Install & login
pip install wandb
wandb login
# Di training_args
training_args = TrainingArguments(
...
report_to="wandb",
run_name="caca-pretrain",
)
# Di training_args
training_args = TrainingArguments(
...
report_to="tensorboard",
)
๐ 6. Resume Training
# Resume dari checkpoint
trainer.train(resume_from_checkpoint="./caca-indo-caca-250m/checkpoint-1000")
# Atau auto-resume dari last checkpoint
trainer.train(resume_from_checkpoint=True)
โ๏ธ 7. Push to Hub
# Login ke Hugging Face
from huggingface_hub import login
login()
# Push model
model.push_to_hub("your-username/caca-indo-caca-250m")
tokenizer.push_to_hub("your-username/caca-indo-caca-250m")
print("โ Model uploaded to Hugging Face Hub!")
๐จ Text Generation Examples
๐ค Basic Generation
from caca_transformers import CacaForCausalLM
from transformers import AutoTokenizer
import torch
# Load model & tokenizer
model = CacaForCausalLM.from_pretrained("your-username/caca-indo-caca-250m")
tokenizer = AutoTokenizer.from_pretrained("your-username/caca-indo-caca-250m")
model.eval()
model.cuda()
# Prepare input
prompt = "Ibu kota Indonesia adalah"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
# Generate
with torch.no_grad():
outputs = model.generate(
input_ids,
max_length=100,
temperature=0.7,
top_p=0.9,
do_sample=True,
use_cache=True, # KV cache untuk speedup
)
# Decode
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
# Analyze each layer
print("๐ Layer-wise parameter count:\n")
layer_total = 0 # โ Ganti nama variable biar gak bentrok
for name, module in model.named_modules():
if isinstance(module, (torch.nn.Linear, torch.nn.Embedding)):
params = sum(p.numel() for p in module.parameters())
layer_total += params
print(f"{name:50s}: {params:>12,} params")
print(f"\n{'='*65}")
print(f"{'Total':50s}: {layer_total:>12,} params") # โ Use layer_total
# Check gradient status
print("\n๐ฏ Gradient status:")
print(f" Trainable: 257,081,216 (100.0%)")
print(f" Frozen: 0 (0.0%)")
โ FAQ (Frequently Asked Questions)
Q: Apakah model ini sudah di-train?
A:
Tidak. Semua model dirilis dengan bobot random dan memerlukan pretraining. Model ini adalah arsitektur kosong yang siap untuk di-train dengan data Anda sendiri.
Model ini cocok untuk:
โ Custom pretraining dengan data domain-spesifik
โ Penelitian arsitektur transformer
โ Pembelajaran tentang LLM
โ
TIDAK
untuk inference langsung
Q: Berapa lama waktu pretraining?
A:
Sangat tergantung ukuran model dan hardware:
Model Size
Hardware
Est. Time
10M-100M
1 GPU (RTX 3090)
1-3 hari
500M-1B
4 GPU (RTX 3090)
1-2 minggu
2B-7B
8 GPU (A100 40GB)
2-4 minggu
13B-30B
32 GPU (A100 80GB)
1-2 bulan
50B-70B
128 GPU (A100 80GB)
2-4 bulan
100B+
512+ GPU cluster
3-6 bulan
Estimasi untuk pretraining dengan ~100B-1T tokens
Q: Dataset apa yang recommended?
A:
Untuk Bahasa Indonesia:
Dataset
Size
rows
Source
Corpus Indonesia Clean
~1.9 GB
~19.5 M
Lyon28/Corpus-Indonesia
Indonesian Wikipedia
~584 MB
~666 K
wikipedia/20220301.id
Common Crawl ID
null
null
Common Crawl filtered
CC100 Indonesian
~8.9 GB
~90 M
cc100/id
Oscar Indonesian
null
null
oscar/unshuffled_deduplicated_id
mC4 Indonesian
null
null
mc4/id
Minimum:
10B tokens untuk model 1B+
Quality > Quantity:
โ Hapus duplikat (MinHash LSH)
โ Filter text berkualitas rendah
โ Balance domains (news, books, web, code)
Q: GPU apa yang dibutuhkan?
A:
Minimum requirements by model size:
Model
Training (BF16+GC)
Inference (FP16)
GPU
10M-100M
2-4GB
<1GB
GTX 1060+
500M-1B
8-16GB
4GB
RTX 3060+
2B-7B
24-48GB
16GB
RTX 3090 / A5000
13B-30B
48GB+
32GB+
A100 40GB
50B-70B
Multi-GPU
Multi-GPU
8ร A100 80GB
100B+
Large cluster
Large cluster
32+ A100 80GB
GC
= Gradient Checkpointing untuk hemat memory
Q: Apakah Flash Attention wajib?
A:
Tidak wajib!
Flash Attention opsional untuk speedup 2-4x.
โ Tidak perlu recompute key/value untuk token sebelumnya
โ Speedup 10-100x untuk autoregressive generation
โ Memory efficient dengan GQA (7x lebih kecil)
Q: Apakah sliding window benar diimplementasikan?
A:
Ya!
Sliding window diimplementasikan di semua backends:
Backend
Implementation
Flash Attention
Native window support via
window_size
parameter
xFormers
Custom attention mask dengan distance-based masking
SDPA
Custom attention mask dengan distance-based masking
Standard
Custom attention mask dengan distance-based masking
Window size model ini:
2,048 tokens
Effective receptive field:
Layer 1: 2,048 tokens
Layer 2: 4,096 tokens
Layer 20: 40,960 tokens
Q: Bagaimana cara fine-tune?
A:
Setelah pretrain, fine-tune dengan
learning rate lebih kecil
:
from transformers import Trainer, TrainingArguments
# Load pretrained model
model = CacaForCausalLM.from_pretrained("Lyon28/caca-250m")
# Fine-tuning args (LR lebih kecil dari pretrain)
training_args = TrainingArguments(
output_dir="./caca-finetuned",
learning_rate=1e-5, # Lebih kecil dari pretrain (3e-4)
num_train_epochs=3,
per_device_train_batch_size=4,
gradient_accumulation_steps=8,
warmup_steps=100,
bf16=True,
gradient_checkpointing=True,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=your_task_dataset,
)
trainer.train()
Tips fine-tuning:
โ Learning rate: 1e-5 hingga 5e-5 (10x lebih kecil dari pretrain)
โ Epoch: 3-5 epoch (jangan terlalu banyak)
โ Warmup: 5-10% dari total steps
โ Monitor validation loss untuk early stopping
Q: Apakah ada pretrained weights?
A:
Belum ada saat ini. Kami sedang merencanakan pretrain untuk:
๐ฎ๐ฉ
Bahasa Indonesia
- Wikipedia, Common Crawl, mC4
# Install Optimum
pip install optimum[onnxruntime]
# Export ke ONNX
from optimum.onnxruntime import ORTModelForCausalLM
model = ORTModelForCausalLM.from_pretrained(
"Lyon28/caca-250m",
export=True,
provider="CUDAExecutionProvider", # Untuk GPU
)
# Save ONNX model
model.save_pretrained("./caca-onnx")
GGUF Support:
Coming soon! ๐ง
Kami sedang mengembangkan converter untuk GGUF format (llama.cpp compatible).
# Dengan Accelerate
from accelerate import Accelerator
accelerator = Accelerator()
model, optimizer, train_dataloader = accelerator.prepare(
model, optimizer, train_dataloader
)
# Dengan DeepSpeed
training_args = TrainingArguments(
deepspeed="ds_config.json",
...
)
โ ๏ธ Keterbatasan
Known Limitations
Model Untrained
- Semua model dirilis dengan random weights, memerlukan pretraining
No Tokenizer
- Belum include tokenizer, anda perlu provide sendiri
Flash Attention Opsional
- Mungkin sulit di-install di beberapa environment
Large Model Training
- Model 70B+ memerlukan multi-node setup
Memory Intensive
- Training memerlukan GPU dengan VRAM besar
Workarounds
# 1. Gunakan tokenizer dari model lain Atau Train Tokenize
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("gpt2")
# 2. Disable Flash Attention jika error
config = CacaConfig(use_flash_attn=False)
# 3. load Model
model = CacaForCausalLM.from_pretrained("Lyon28/caca-250m")
# 4. Gradient checkpointing untuk model besar
model.gradient_checkpointing_enable()
# 5. 8-bit training untuk hemat memory
from transformers import BitsAndBytesConfig
config = BitsAndBytesConfig(load_in_8bit=True)
๐ Lisensi
Apache License 2.0
- Bebas digunakan untuk keperluan komersial dan penelitian.
caca-250m huggingface.co is an AI model on huggingface.co that provides caca-250m's model effect (), which can be used instantly with this Lyon28 caca-250m model. huggingface.co supports a free trial of the caca-250m model, and also provides paid use of the caca-250m. Support call caca-250m model through api, including Node.js, Python, http.
caca-250m huggingface.co is an online trial and call api platform, which integrates caca-250m's modeling effects, including api services, and provides a free online trial of caca-250m, you can try caca-250m online for free by clicking the link below.
Lyon28 caca-250m online free url in huggingface.co:
caca-250m is an open source model from GitHub that offers a free installation service, and any user can find caca-250m on GitHub to install. At the same time, huggingface.co provides the effect of caca-250m install, users can directly use caca-250m installed effect in huggingface.co for debugging and trial. It also supports api for free installation.