Upload README (2).md
Browse files- README (2).md +86 -0
README (2).md
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
pipeline_tag: text-generation
|
4 |
+
library_name: transformers
|
5 |
+
---
|
6 |
+
CURRENTLY IN TRAINING :)
|
7 |
+
|
8 |
+
Currently, only the LLM section of this model is fully ready.
|
9 |
+
```py
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
11 |
+
import torch
|
12 |
+
|
13 |
+
# Load model and tokenizer
|
14 |
+
model_name = "Abhaykoul/hai3.1-pretrainedv3"
|
15 |
+
|
16 |
+
# Set device to CUDA if available
|
17 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
+
|
19 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True, torch_dtype="auto")
|
20 |
+
model.to(device)
|
21 |
+
print(model)
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
23 |
+
|
24 |
+
# Message role format for chat
|
25 |
+
messages = [
|
26 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
27 |
+
{"role": "user", "content": """hlo"""},
|
28 |
+
]
|
29 |
+
|
30 |
+
# Apply chat template to format prompt
|
31 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
32 |
+
|
33 |
+
# Tokenize input and move to device
|
34 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
35 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
36 |
+
|
37 |
+
# Set up text streamer for live output
|
38 |
+
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
|
39 |
+
|
40 |
+
# Generate text with streaming
|
41 |
+
model.generate(
|
42 |
+
**inputs,
|
43 |
+
max_new_tokens=4089,
|
44 |
+
temperature=0.7,
|
45 |
+
top_p=0.9,
|
46 |
+
do_sample=True,
|
47 |
+
streamer=streamer
|
48 |
+
)
|
49 |
+
```
|
50 |
+
Classfication section undertraining
|
51 |
+
```py
|
52 |
+
import torch
|
53 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
54 |
+
|
55 |
+
ckpt = "Abhaykoul/hai3.1-pretrainedv3"
|
56 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
57 |
+
|
58 |
+
model = AutoModelForCausalLM.from_pretrained(ckpt, trust_remote_code=True).to(device).eval()
|
59 |
+
tok = AutoTokenizer.from_pretrained(ckpt, trust_remote_code=True)
|
60 |
+
if tok.pad_token is None:
|
61 |
+
tok.pad_token = tok.eos_token
|
62 |
+
|
63 |
+
text = "I am thrilled about my new job!"
|
64 |
+
enc = tok([text], padding=True, truncation=True, max_length=2048, return_tensors="pt")
|
65 |
+
enc = {k: v.to(device) for k, v in enc.items()}
|
66 |
+
|
67 |
+
with torch.no_grad():
|
68 |
+
out = model(input_ids=enc["input_ids"], attention_mask=enc.get("attention_mask"), output_hidden_states=True, return_dict=True, use_cache=False)
|
69 |
+
last = out.hidden_states[-1]
|
70 |
+
idx = (enc["attention_mask"].sum(dim=1) - 1).clamp(min=0)
|
71 |
+
pooled = last[torch.arange(last.size(0)), idx]
|
72 |
+
logits = model.structured_lm_head(pooled)
|
73 |
+
pred_id = logits.argmax(dim=-1).item()
|
74 |
+
|
75 |
+
print("Predicted class id:", pred_id)
|
76 |
+
# Map id -> label using your dataset’s label list, e.g.:
|
77 |
+
id2label = ["sadness","joy","love","anger","fear","surprise"] # dair-ai/emotion
|
78 |
+
print("Predicted label:", id2label[pred_id] if pred_id < len(id2label) else "unknown")
|
79 |
+
```
|
80 |
+
|
81 |
+
TTS layers in training
|
82 |
+
|
83 |
+
NOTE: we have used qwen2 tokenizer in it
|
84 |
+
|
85 |
+
This model contains layers from our diffrent models
|
86 |
+
To aline layers we have done post training after merging layers
|