akkiisfrommars commited on
Commit
f555625
·
verified ·
1 Parent(s): 33b3450

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -57
README.md CHANGED
@@ -3,22 +3,43 @@ license: apache-2.0
3
  tags:
4
  - text-generation
5
  - language-model
6
- - LLM
7
- - CosmicFish
8
- - 120M
9
  - transformer
 
 
 
 
10
  language: en
11
  datasets:
12
  - CosmicSet-1.0
13
- - akkiisfrommars/TreeCorpusCleaned
14
  model_type: CosmicFish
 
15
  ---
16
 
17
-
18
  # CosmicFish-120M
19
 
20
  A 120M parameter language model with modern architecture improvements developed by Mistyoz AI.
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ## Model Details
23
 
24
  - **Parameters**: 121M
@@ -27,6 +48,7 @@ A 120M parameter language model with modern architecture improvements developed
27
  - **Vocabulary**: 50,257 tokens
28
  - **Training Data**: CosmicSet 1.0
29
  - **Developer**: Mistyoz AI
 
30
 
31
  ## Usage
32
 
@@ -36,52 +58,62 @@ A 120M parameter language model with modern architecture improvements developed
36
  pip install transformers huggingface-hub termcolor
37
  ```
38
 
39
- ### Loading the Model
40
 
41
  ```python
 
 
42
  import torch
43
  import json
44
- from transformers import GPT2Tokenizer
45
- from modeling_cosmicfish import CosmicFish, CosmicConfig
46
-
47
- # Load model
48
- with open("config.json") as f:
49
- config_dict = json.load(f)
50
 
51
- config = CosmicConfig(**{k: v for k, v in config_dict.items() if k in [
52
- 'vocab_size', 'block_size', 'n_layer', 'n_head', 'n_embd', 'bias',
53
- 'use_rotary', 'use_swiglu', 'use_gqa', 'n_query_groups'
54
- ]})
55
- config.dropout = 0.0 # Inference mode
56
-
57
- model = CosmicFish(config)
58
- model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
59
- model.eval()
60
 
61
  # Load tokenizer
62
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
 
 
 
 
 
 
 
 
 
 
63
  ```
64
 
65
- ### Basic Generation
66
 
67
  ```python
68
- def generate_text(prompt, max_tokens=100):
69
- inputs = tokenizer.encode(prompt, return_tensors="pt")
 
70
 
71
- with torch.no_grad():
72
- outputs = model.generate(
73
- inputs,
74
- max_new_tokens=max_tokens,
75
- temperature=0.7,
76
- top_k=40,
77
- do_sample=True
78
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
81
-
82
- # Example
83
- text = generate_text("The future of AI is")
84
- print(text)
85
  ```
86
 
87
  ### Chat Interface
@@ -95,31 +127,21 @@ def chat_with_model():
95
  if user_input.lower() in ['quit', 'exit']:
96
  break
97
 
98
-
99
  context = "Below is a conversation between a human and an AI assistant.\n\n"
100
  for human, ai in conversation:
101
  context += f"Human: {human}\nAssistant: {ai}\n\n"
102
  context += f"Human: {user_input}\nAssistant:"
103
 
104
- # Generate response
105
- inputs = tokenizer.encode(context, return_tensors="pt")
106
- if inputs.shape[1] > 400:
107
- inputs = inputs[:, -400:]
108
-
109
- with torch.no_grad():
110
- outputs = model.generate(
111
- inputs,
112
- max_new_tokens=150,
113
- temperature=0.7,
114
- top_k=40,
115
- do_sample=True,
116
- pad_token_id=tokenizer.eos_token_id
117
- )
118
-
119
- response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
120
- response = response.split('\n')[0].strip()
121
 
 
 
122
  print(f"CosmicFish: {response}")
 
123
  conversation.append((user_input, response))
124
 
125
  chat_with_model()
@@ -130,7 +152,7 @@ chat_with_model()
130
  CosmicFish uses several modern improvements over standard transformers:
131
 
132
  - **RoPE (Rotary Position Embeddings)**: Better position encoding than absolute positions
133
- - **GQA (Grouped-Query Attention)**: Reduces memory usage with 4 query groups
134
  - **SwiGLU**: More effective activation function than ReLU/GELU
135
  - **RMSNorm**: Simpler, more stable normalization than LayerNorm
136
 
@@ -148,6 +170,7 @@ CosmicFish uses several modern improvements over standard transformers:
148
  - **File Size**: 243MB
149
 
150
  ## Limitations
 
151
  - Small model size (120M parameters) may produce less accurate responses
152
  - 512 token context limit
153
  - Training data cutoff applies
@@ -158,6 +181,6 @@ CosmicFish uses several modern improvements over standard transformers:
158
 
159
  Apache 2.0 - see LICENSE file.
160
 
161
-
162
  ## Credit
 
163
  If you use CosmicFish-120M, please credit Mistyoz AI.
 
3
  tags:
4
  - text-generation
5
  - language-model
6
+ - causal-lm
7
+ - cosmicfish
8
+ - 120m
9
  - transformer
10
+ - rope
11
+ - gqa
12
+ - swiglu
13
+ - rmsnorm
14
  language: en
15
  datasets:
16
  - CosmicSet-1.0
17
+ - akkiisfrommars/TreeCorpusCleanedmodel
18
  model_type: CosmicFish
19
+ pipeline_tag: text-generation
20
  ---
21
 
 
22
  # CosmicFish-120M
23
 
24
  A 120M parameter language model with modern architecture improvements developed by Mistyoz AI.
25
 
26
+ ## Quick Start
27
+
28
+ **The easiest way to chat with CosmicFish is using our chat.py script:**
29
+
30
+ ```bash
31
+ # Download the chat script from this repository
32
+ wget https://huggingface.co/MistyozAI/CosmicFish-120M/resolve/main/chat.py
33
+
34
+ # Install dependencies
35
+ pip install transformers huggingface-hub termcolor
36
+
37
+ # Run the chat interface (automatically downloads model)
38
+ python chat.py
39
+ ```
40
+
41
+ The `chat.py` script handles all model loading, generation, and provides the best chat experience with live streaming, repetition penalty, and conversation commands.
42
+
43
  ## Model Details
44
 
45
  - **Parameters**: 121M
 
48
  - **Vocabulary**: 50,257 tokens
49
  - **Training Data**: CosmicSet 1.0
50
  - **Developer**: Mistyoz AI
51
+ - **Repository**: MistyozAI/CosmicFish-120M
52
 
53
  ## Usage
54
 
 
58
  pip install transformers huggingface-hub termcolor
59
  ```
60
 
61
+ ### Quick Chat Interface
62
 
63
  ```python
64
+ from transformers import GPT2Tokenizer
65
+ from huggingface_hub import snapshot_download
66
  import torch
67
  import json
68
+ import os
 
 
 
 
 
69
 
70
+ # Download model from Hugging Face Hub
71
+ cache_dir = snapshot_download(repo_id="MistyozAI/CosmicFish-120M")
 
 
 
 
 
 
 
72
 
73
  # Load tokenizer
74
  tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
75
+
76
+ # Load config
77
+ with open(os.path.join(cache_dir, "config.json")) as f:
78
+ config_dict = json.load(f)
79
+
80
+ # Load model weights
81
+ state_dict = torch.load(os.path.join(cache_dir, "pytorch_model.bin"), map_location="cpu")
82
+
83
+ # Note: Full model class available in the repository
84
+ print("Model downloaded and ready for use!")
85
  ```
86
 
87
+ ### Advanced Generation with Repetition Penalty
88
 
89
  ```python
90
+ def generate_with_repetition_penalty(model, tokenizer, prompt, max_tokens=100, temperature=0.7, penalty=1.2):
91
+ input_ids = torch.tensor(tokenizer.encode(prompt)).unsqueeze(0)
92
+ generated = input_ids.clone()
93
 
94
+ for _ in range(max_tokens):
95
+ with torch.no_grad():
96
+ logits, _ = model(generated)
97
+
98
+ next_token_logits = logits[:, -1, :] / temperature
99
+
100
+ # Apply repetition penalty
101
+ if penalty > 1.0:
102
+ for token_id in set(generated[0].tolist()):
103
+ if next_token_logits[0, token_id] > 0:
104
+ next_token_logits[0, token_id] /= penalty
105
+ else:
106
+ next_token_logits[0, token_id] *= penalty
107
+
108
+ probs = torch.nn.functional.softmax(next_token_logits, dim=-1)
109
+ next_token = torch.multinomial(probs, num_samples=1)
110
+
111
+ if next_token.item() == tokenizer.eos_token_id:
112
+ break
113
+
114
+ generated = torch.cat([generated, next_token], dim=1)
115
 
116
+ return tokenizer.decode(generated[0], skip_special_tokens=True)
 
 
 
 
117
  ```
118
 
119
  ### Chat Interface
 
127
  if user_input.lower() in ['quit', 'exit']:
128
  break
129
 
 
130
  context = "Below is a conversation between a human and an AI assistant.\n\n"
131
  for human, ai in conversation:
132
  context += f"Human: {human}\nAssistant: {ai}\n\n"
133
  context += f"Human: {user_input}\nAssistant:"
134
 
135
+ # Generate response with repetition penalty
136
+ response = generate_with_repetition_penalty(
137
+ model, tokenizer, context,
138
+ max_tokens=150, temperature=0.7, penalty=1.2
139
+ )
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
+ # Extract just the assistant's response
142
+ response = response.split("Assistant:")[-1].split('\n')[0].strip()
143
  print(f"CosmicFish: {response}")
144
+
145
  conversation.append((user_input, response))
146
 
147
  chat_with_model()
 
152
  CosmicFish uses several modern improvements over standard transformers:
153
 
154
  - **RoPE (Rotary Position Embeddings)**: Better position encoding than absolute positions
155
+ - **GQA (Grouped-Query Attention)**: Reduces memory usage with 4 query groups
156
  - **SwiGLU**: More effective activation function than ReLU/GELU
157
  - **RMSNorm**: Simpler, more stable normalization than LayerNorm
158
 
 
170
  - **File Size**: 243MB
171
 
172
  ## Limitations
173
+
174
  - Small model size (120M parameters) may produce less accurate responses
175
  - 512 token context limit
176
  - Training data cutoff applies
 
181
 
182
  Apache 2.0 - see LICENSE file.
183
 
 
184
  ## Credit
185
+
186
  If you use CosmicFish-120M, please credit Mistyoz AI.