Adapters
Safetensors
llama

Upload README.md

#6
by tarantula11 - opened
Files changed (1) hide show
  1. README.md +54 -11
README.md CHANGED
@@ -1,15 +1,6 @@
1
- ---
2
- license: mit
3
- datasets:
4
- - ai-factory/red_pajama_subset_arxiv_subset
5
- - ai-factory/glaiveai-reasoning-v1-20m-chat
6
- base_model:
7
- - meta-llama/Llama-3.2-3B
8
- library_name: asteroid
9
- ---
10
  # πŸš€ Full Finetuned LLaMA 3.2 3B for AI Factory
11
 
12
- This model combines the base `full_finetuned_llama3b` with LoRA fine-tuning on:
13
  - `ai-factory/red_pajama_subset_arxiv_subset`
14
  - `ai-factory/glaiveai-reasoning-v1-20m-chat`
15
 
@@ -22,10 +13,62 @@ This model combines the base `full_finetuned_llama3b` with LoRA fine-tuning on:
22
  from transformers import AutoTokenizer, AutoModelForCausalLM
23
  model = AutoModelForCausalLM.from_pretrained("your-hf-username/full_finetuned_llama3b")
24
  tokenizer = AutoTokenizer.from_pretrained("ai-factory/giant")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ```
26
 
27
  ## πŸ‘€ Authors
28
  - AI Factory Miner Submission
29
 
30
  ## πŸ“š License
31
- - Meta LLaMA license
 
 
 
 
 
 
 
 
 
 
1
  # πŸš€ Full Finetuned LLaMA 3.2 3B for AI Factory
2
 
3
+ This model combines the base `/mnt/i/sub80/merged/2/ai_factory/full_finetuned_llama3b` with LoRA fine-tuning on:
4
  - `ai-factory/red_pajama_subset_arxiv_subset`
5
  - `ai-factory/glaiveai-reasoning-v1-20m-chat`
6
 
 
13
  from transformers import AutoTokenizer, AutoModelForCausalLM
14
  model = AutoModelForCausalLM.from_pretrained("your-hf-username/full_finetuned_llama3b")
15
  tokenizer = AutoTokenizer.from_pretrained("ai-factory/giant")
16
+ # Load base model
17
+ base_model = AutoModelForCausalLM.from_pretrained(
18
+ BASE_MODEL,
19
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
20
+ device_map="auto",
21
+ trust_remote_code=True,
22
+ use_safetensors=True,
23
+ local_files_only=True
24
+ )
25
+
26
+ # Apply LoRA
27
+ peft_config = LoraConfig(
28
+ task_type=TaskType.CAUSAL_LM,
29
+ r=8,
30
+ lora_alpha=32,
31
+ lora_dropout=0.05,
32
+ bias="none",
33
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]
34
+ )
35
+ model = get_peft_model(base_model, peft_config)
36
+ model.eval()
37
+ if torch.cuda.is_available():
38
+ model = model.cuda()
39
+
40
+ # Load streaming datasets
41
+ arxiv = load_dataset("ai-factory/red_pajama_subset_arxiv_subset", split="train", streaming=True)
42
+ glaive = load_dataset("ai-factory/glaiveai-reasoning-v1-20m-chat", split="train", streaming=True)
43
+
44
+ def tokenize(example):
45
+ return tokenizer(example["text"], truncation=True, max_length=4096)
46
+
47
+ # Tokenize small samples
48
+ tokenized_arxiv = map(tokenize, islice(arxiv, args.sample_size))
49
+ tokenized_glaive = map(tokenize, islice(glaive, args.sample_size))
50
+
51
+ # Run forward + backward pass (init LoRA weights)
52
+ print("πŸ”₯ Training one step to initialize LoRA...")
53
+ for i, sample in enumerate(tokenized_arxiv):
54
+ if not sample.get("input_ids"):
55
+ continue
56
+ ids = torch.tensor(sample["input_ids"]).unsqueeze(0).to(model.device)
57
+ labels = ids.clone()
58
+ loss = model(input_ids=ids, labels=labels).loss
59
+ loss.backward()
60
+ break
61
+
62
+ # Merge LoRA and save
63
+ print("πŸ” Merging adapter into base model...")
64
+ merged_model = model.merge_and_unload()
65
+ merged_model.save_pretrained(SAVE_DIR, safe_serialization=True)
66
+ tokenizer.save_pretrained(SAVE_DIR)
67
+ print(f"βœ… Merged model saved to {SAVE_DIR}")
68
  ```
69
 
70
  ## πŸ‘€ Authors
71
  - AI Factory Miner Submission
72
 
73
  ## πŸ“š License
74
+ - Meta LLaMA license