π Full Finetuned Qwen1.5-4B for AI Factory
This model combines the base Qwen/Qwen1.5-4B
with LoRA fine-tuning on:
π Training and Testing Data:
ai-factory/red_pajama_subset_arxiv_subset
: ArXiv papers truncated to 4096-token chunks.ai-factory/red_pajama_subset_stackexchange_subset
: Samples are formatted using a chat template with two roles:user
(representing questions) andother
(representing answers).ai-factory/glaiveai-reasoning-v1-20m-chat
: Samples are formatted using a chat template with two roles:user
(representing questions) andme
(representing the AI).- β Tokenizer: ai-factory/giant
- π Adapter format: QLoRA (PEFT)
- π§ͺ Torch dtype
π Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("your-hf-username/full_finetuned_qwen4b")
tokenizer = AutoTokenizer.from_pretrained("ai-factory/giant")
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token if tokenizer.pad_token is None else tokenizer.pad_token
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
device_map="auto",
trust_remote_code=True,
use_safetensors=True,
local_files_only=True
)
# Apply LoRA
peft_config = LoraConfig(
task_type=TaskType.CAUSAL_LM,
r=8,
lora_alpha=32,
lora_dropout=0.05,
bias="none",
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]
)
model = get_peft_model(base_model, peft_config)
model.eval()
if torch.cuda.is_available():
model = model.cuda()
# Load streaming datasets
arxiv = load_dataset("ai-factory/red_pajama_subset_arxiv_subset", split="train", streaming=True)
glaive = load_dataset("ai-factory/glaiveai-reasoning-v1-20m-chat", split="train", streaming=True)
stack = load_dataset("ai-factory/red_pajama_subset_stackexchange_subset", split="train", streaming=True)
def tokenize(example):
return tokenizer(example["text"], truncation=True, max_length=4096)
# Tokenize small samples
tokenized_arxiv = map(tokenize, islice(arxiv, args.sample_size))
tokenized_glaive = map(tokenize, islice(glaive, args.sample_size))
tokenized_stack = map(tokenize, islice(stack, args.sample_size))
# Run forward + backward pass (init LoRA weights)
print("π₯ Training one step to initialize LoRA...")
for i, sample in enumerate(tokenized_arxiv):
if not sample.get("input_ids"):
continue
ids = torch.tensor(sample["input_ids"]).unsqueeze(0).to(model.device)
labels = ids.clone()
loss = model(input_ids=ids, labels=labels).loss
loss.backward()
break
# Merge LoRA and save
print("π Merging adapter into base model...")
merged_model = model.merge_and_unload()
merged_model.save_pretrained(SAVE_DIR, safe_serialization=True)
tokenizer.save_pretrained(SAVE_DIR)
print(f"β
Merged model saved to /mnt/i/sub80/merged/3/ai_factory/full_finetuned_qwen4b")
π€ Authors
- AI Factory Miner Submission
π License
- Qwen license
- Downloads last month
- -
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support
Model tree for tarantulas/Finetuned_Qwen1.5-4b
Base model
Qwen/Qwen1.5-4B