MaagDeveloper commited on
Commit
2cf5ae9
·
verified ·
1 Parent(s): b3743ea

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -16
README.md CHANGED
@@ -21,7 +21,7 @@ library_name: transformers
21
 
22
  **NeoLM-Small-Base** is an English-focused, decoder-only Transformer language model trained from scratch with PyTorch and Hugging Face Transformers. This repository publishes the **Stage 1 Foundation** base-model checkpoint in **bfloat16** format. It is a **base next-token prediction model**, not an instruction-tuned chat assistant.
23
 
24
- The fixed Foundation release can be loaded using the `stage1-foundation` revision after the release tag is created.
25
 
26
  ## Architecture
27
 
@@ -82,7 +82,6 @@ This is a released training checkpoint rather than a claim of complete convergen
82
  Install compatible versions of `torch` and `transformers`. The model requires custom Python code, so review the repository code before enabling `trust_remote_code=True`.
83
 
84
  ```python
85
- import torch
86
  from transformers import AutoTokenizer, AutoModelForCausalLM
87
 
88
  repo_id = "MaagDeveloper/NeoLM-Small-Base"
@@ -91,28 +90,79 @@ revision = "stage1-foundation"
91
  tokenizer = AutoTokenizer.from_pretrained(
92
  repo_id, revision=revision, trust_remote_code=True
93
  )
 
94
  model = AutoModelForCausalLM.from_pretrained(
95
  repo_id, revision=revision, trust_remote_code=True,
96
- dtype=torch.bfloat16,
97
  ).eval()
98
 
99
- # For a CPU that does not support BF16 well, load with dtype=torch.float32 instead.
100
  prompt = "The future of artificial intelligence"
101
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=1024)
102
- with torch.no_grad():
103
- outputs = model.generate(
104
- **inputs,
105
- max_new_tokens=64,
106
- do_sample=True,
107
- temperature=0.8,
108
- top_p=0.9,
109
- repetition_penalty=1.15,
110
- eos_token_id=tokenizer.eos_token_id,
111
- pad_token_id=tokenizer.pad_token_id,
112
- )
 
 
 
 
113
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
114
  ```
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  The code above is **text completion**, not role-based chat. NeoLM-Small-Base may not reliably follow instructions, answer factual questions, or perform multi-step reasoning. A separate instruction-tuned model belongs in a distinct repository.
117
 
118
  ## Evaluation and limitations
 
21
 
22
  **NeoLM-Small-Base** is an English-focused, decoder-only Transformer language model trained from scratch with PyTorch and Hugging Face Transformers. This repository publishes the **Stage 1 Foundation** base-model checkpoint in **bfloat16** format. It is a **base next-token prediction model**, not an instruction-tuned chat assistant.
23
 
24
+ The fixed Foundation release can be loaded using the `stage1-foundation` revision.
25
 
26
  ## Architecture
27
 
 
82
  Install compatible versions of `torch` and `transformers`. The model requires custom Python code, so review the repository code before enabling `trust_remote_code=True`.
83
 
84
  ```python
 
85
  from transformers import AutoTokenizer, AutoModelForCausalLM
86
 
87
  repo_id = "MaagDeveloper/NeoLM-Small-Base"
 
90
  tokenizer = AutoTokenizer.from_pretrained(
91
  repo_id, revision=revision, trust_remote_code=True
92
  )
93
+
94
  model = AutoModelForCausalLM.from_pretrained(
95
  repo_id, revision=revision, trust_remote_code=True,
96
+ dtype="auto",
97
  ).eval()
98
 
99
+ # For a CPU that does not support BF16 well, use dtype=torch.float32 instead.
100
  prompt = "The future of artificial intelligence"
101
+
102
+ inputs = tokenizer(
103
+ prompt, return_tensors="pt", truncation=True, max_length=1024
104
+ )
105
+
106
+ outputs = model.generate(
107
+ **inputs,
108
+ max_new_tokens=64,
109
+ do_sample=True,
110
+ temperature=0.8,
111
+ top_p=0.9,
112
+ repetition_penalty=1.15,
113
+ eos_token_id=tokenizer.eos_token_id,
114
+ pad_token_id=tokenizer.pad_token_id,
115
+ )
116
+
117
  print(tokenizer.decode(outputs[0], skip_special_tokens=True))
118
  ```
119
 
120
+
121
+ ## Streaming Text Generation
122
+
123
+ You can stream generated text progressively using Hugging Face Transformers' `TextStreamer`.
124
+
125
+ ```python
126
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
127
+
128
+ repo_id = "MaagDeveloper/NeoLM-Small-Base"
129
+ revision = "stage1-foundation"
130
+
131
+ tokenizer = AutoTokenizer.from_pretrained(
132
+ repo_id,
133
+ revision=revision,
134
+ trust_remote_code=True,
135
+ )
136
+
137
+ model = AutoModelForCausalLM.from_pretrained(
138
+ repo_id,
139
+ revision=revision,
140
+ trust_remote_code=True,
141
+ dtype="auto",
142
+ ).eval()
143
+
144
+ streamer = TextStreamer(
145
+ tokenizer,
146
+ skip_prompt=False,
147
+ skip_special_tokens=True,
148
+ )
149
+
150
+ prompt = "Once upon a time"
151
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
152
+
153
+ model.generate(
154
+ **inputs,
155
+ streamer=streamer,
156
+ max_new_tokens=100,
157
+ do_sample=True,
158
+ temperature=0.8,
159
+ top_p=0.9,
160
+ repetition_penalty=1.15,
161
+ eos_token_id=tokenizer.eos_token_id,
162
+ pad_token_id=tokenizer.pad_token_id,
163
+ )
164
+ ```
165
+
166
  The code above is **text completion**, not role-based chat. NeoLM-Small-Base may not reliably follow instructions, answer factual questions, or perform multi-step reasoning. A separate instruction-tuned model belongs in a distinct repository.
167
 
168
  ## Evaluation and limitations