Text Generation
Transformers
Safetensors
PyTorch
English
fineweb_decoder
causal-lm
custom-code
educational
custom_code
Instructions to use PeterRabbit/fineweb-12m-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use PeterRabbit/fineweb-12m-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="PeterRabbit/fineweb-12m-base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("PeterRabbit/fineweb-12m-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use PeterRabbit/fineweb-12m-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "PeterRabbit/fineweb-12m-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "PeterRabbit/fineweb-12m-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/PeterRabbit/fineweb-12m-base
- SGLang
How to use PeterRabbit/fineweb-12m-base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "PeterRabbit/fineweb-12m-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "PeterRabbit/fineweb-12m-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "PeterRabbit/fineweb-12m-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "PeterRabbit/fineweb-12m-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use PeterRabbit/fineweb-12m-base with Docker Model Runner:
docker model run hf.co/PeterRabbit/fineweb-12m-base
Publish model weights, tokenizer, code, and model card
Browse files- LICENSE +201 -0
- README.md +97 -0
- config.json +25 -0
- configuration_fineweb.py +34 -0
- generate.py +56 -0
- generation_config.json +10 -0
- model.safetensors +3 -0
- modeling_fineweb.py +155 -0
- requirements.txt +5 -0
- tokenizer.json +0 -0
- tokenizer_config.json +9 -0
LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
library_name: transformers
|
| 7 |
+
datasets:
|
| 8 |
+
- HuggingFaceFW/fineweb-edu
|
| 9 |
+
tags:
|
| 10 |
+
- causal-lm
|
| 11 |
+
- custom-code
|
| 12 |
+
- educational
|
| 13 |
+
- pytorch
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# FineWeb 12M Base
|
| 17 |
+
|
| 18 |
+
A 12.2M-parameter decoder-only base language model trained from scratch on FineWeb-Edu.
|
| 19 |
+
|
| 20 |
+
> This is a small educational and experimental model. It is not a production assistant and should not be relied on for factual, medical, legal, financial, safety-critical, or other consequential advice.
|
| 21 |
+
|
| 22 |
+
## Model details
|
| 23 |
+
|
| 24 |
+
| Property | Value |
|
| 25 |
+
|---|---:|
|
| 26 |
+
| Parameters | 12,194,048 |
|
| 27 |
+
| Layers | 8 |
|
| 28 |
+
| Hidden width | 256 |
|
| 29 |
+
| Attention heads | 4 |
|
| 30 |
+
| SwiGLU hidden width | 960 |
|
| 31 |
+
| Vocabulary | 16,384 BPE tokens |
|
| 32 |
+
| Context window | 1,024 tokens |
|
| 33 |
+
| Architecture | Decoder-only Transformer |
|
| 34 |
+
| Position encoding | RoPE |
|
| 35 |
+
| Normalization | RMSNorm |
|
| 36 |
+
| Embeddings | Tied input/output embeddings |
|
| 37 |
+
|
| 38 |
+
The architecture was implemented from scratch in PyTorch. This repository includes custom Transformers-compatible configuration and modeling files.
|
| 39 |
+
|
| 40 |
+
## Training
|
| 41 |
+
|
| 42 |
+
The base model was trained from scratch on 2,883,059,712 packed tokens selected from the FineWeb-Edu `sample-10BT` corpus. Documents were selected deterministically by hashing document IDs rather than taking the first source shards. Text was tokenized with a locally trained byte-level BPE tokenizer, an `<eos>` token was appended after every document, and tokens were packed into fixed 1,024-token blocks.
|
| 43 |
+
|
| 44 |
+
Base training used AdamW, cosine learning-rate decay, gradient clipping, bfloat16 autocast, and a global batch size of 65,536 tokens on an NVIDIA RTX 3090.
|
| 45 |
+
|
| 46 |
+
## Evaluation
|
| 47 |
+
|
| 48 |
+
Best validation loss: 3.4330 (next-token validation).
|
| 49 |
+
|
| 50 |
+
These losses are internal held-out validation measurements. Base and SFT losses use different objectives, and losses from the 8K and 16K tokenizers are not directly comparable. No broad academic benchmark suite or human preference evaluation was run.
|
| 51 |
+
|
| 52 |
+
## Usage
|
| 53 |
+
|
| 54 |
+
Install the dependencies:
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
pip install -r requirements.txt
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
Run the included example after cloning this repository:
|
| 61 |
+
|
| 62 |
+
```bash
|
| 63 |
+
python generate.py --model . --prompt "The purpose of education is"
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
Or load it through Transformers:
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
from transformers import AutoModelForCausalLM
|
| 70 |
+
|
| 71 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 72 |
+
".",
|
| 73 |
+
trust_remote_code=True,
|
| 74 |
+
)
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
`trust_remote_code=True` is required because this is a custom architecture. Review `configuration_fineweb.py` and `modeling_fineweb.py` before loading code from the Hub.
|
| 78 |
+
|
| 79 |
+
## Limitations
|
| 80 |
+
|
| 81 |
+
- The model is very small by modern language-model standards and often produces incorrect, repetitive, incoherent, or fabricated text.
|
| 82 |
+
- Its knowledge is limited to patterns learned from the training data; it has no live information retrieval, tools, memory, or reliable sense of current time.
|
| 83 |
+
- The 1,024-token context window includes both the prompt and generated output.
|
| 84 |
+
- FineWeb-Edu is English-focused web data and can contain errors, biases, sensitive material, and uneven topic coverage.
|
| 85 |
+
- The SFT variants received a small amount of instruction tuning and are not robust chat assistants.
|
| 86 |
+
- The model has not been evaluated for safety, fairness, memorization, or production deployment.
|
| 87 |
+
|
| 88 |
+
## Training data and attribution
|
| 89 |
+
|
| 90 |
+
- [FineWeb-Edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu), licensed ODC-By 1.0, was used for base pretraining.
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
The source datasets are not redistributed in this model repository and remain subject to their respective licences and attribution requirements.
|
| 94 |
+
|
| 95 |
+
## Licence
|
| 96 |
+
|
| 97 |
+
The model weights and original code in this repository are released under the Apache License 2.0. This does not replace or override the licences of the training datasets.
|
config.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"FineWebForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "configuration_fineweb.FineWebConfig",
|
| 7 |
+
"AutoModelForCausalLM": "modeling_fineweb.FineWebForCausalLM"
|
| 8 |
+
},
|
| 9 |
+
"model_type": "fineweb_decoder",
|
| 10 |
+
"vocab_size": 16384,
|
| 11 |
+
"n_layers": 8,
|
| 12 |
+
"d_model": 256,
|
| 13 |
+
"n_heads": 4,
|
| 14 |
+
"mlp_hidden": 960,
|
| 15 |
+
"context_length": 1024,
|
| 16 |
+
"max_position_embeddings": 1024,
|
| 17 |
+
"rms_norm_eps": 1e-06,
|
| 18 |
+
"bos_token_id": 0,
|
| 19 |
+
"eos_token_id": 1,
|
| 20 |
+
"pad_token_id": 1,
|
| 21 |
+
"unk_token_id": 2,
|
| 22 |
+
"tie_word_embeddings": true,
|
| 23 |
+
"use_cache": false,
|
| 24 |
+
"torch_dtype": "float32"
|
| 25 |
+
}
|
configuration_fineweb.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hugging Face configuration for the educational FineWeb decoder."""
|
| 2 |
+
|
| 3 |
+
from transformers import PreTrainedConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class FineWebConfig(PreTrainedConfig):
|
| 7 |
+
model_type = "fineweb_decoder"
|
| 8 |
+
|
| 9 |
+
def __init__(
|
| 10 |
+
self,
|
| 11 |
+
vocab_size=16384,
|
| 12 |
+
n_layers=8,
|
| 13 |
+
d_model=256,
|
| 14 |
+
n_heads=4,
|
| 15 |
+
mlp_hidden=960,
|
| 16 |
+
context_length=1024,
|
| 17 |
+
rms_norm_eps=1e-6,
|
| 18 |
+
**kwargs,
|
| 19 |
+
):
|
| 20 |
+
kwargs.setdefault("tie_word_embeddings", True)
|
| 21 |
+
kwargs.setdefault("use_cache", False)
|
| 22 |
+
super().__init__(**kwargs)
|
| 23 |
+
self.vocab_size = vocab_size
|
| 24 |
+
self.n_layers = n_layers
|
| 25 |
+
self.d_model = d_model
|
| 26 |
+
self.n_heads = n_heads
|
| 27 |
+
self.mlp_hidden = mlp_hidden
|
| 28 |
+
self.context_length = context_length
|
| 29 |
+
self.max_position_embeddings = context_length
|
| 30 |
+
self.rms_norm_eps = rms_norm_eps
|
| 31 |
+
self.hidden_size = d_model
|
| 32 |
+
self.num_hidden_layers = n_layers
|
| 33 |
+
self.num_attention_heads = n_heads
|
| 34 |
+
|
generate.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Load the model from this folder (or the Hub) and generate text."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from tokenizers import Tokenizer
|
| 7 |
+
import transformers
|
| 8 |
+
from transformers import AutoModelForCausalLM
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
parser = argparse.ArgumentParser()
|
| 13 |
+
parser.add_argument("--model", default=".", help="Local folder or Hugging Face model ID")
|
| 14 |
+
parser.add_argument("--prompt", default="The purpose of education is")
|
| 15 |
+
parser.add_argument("--max-new-tokens", type=int, default=128)
|
| 16 |
+
parser.add_argument("--temperature", type=float, default=0.8)
|
| 17 |
+
parser.add_argument("--top-k", type=int, default=40)
|
| 18 |
+
args = parser.parse_args()
|
| 19 |
+
|
| 20 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 21 |
+
dtype = torch.bfloat16 if device.type == "cuda" else torch.float32
|
| 22 |
+
dtype_arg = (
|
| 23 |
+
{"dtype": dtype}
|
| 24 |
+
if int(transformers.__version__.split(".", 1)[0]) >= 5
|
| 25 |
+
else {"torch_dtype": dtype}
|
| 26 |
+
)
|
| 27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 28 |
+
args.model, trust_remote_code=True, **dtype_arg
|
| 29 |
+
).to(device).eval()
|
| 30 |
+
tokenizer_path = args.model + "/tokenizer.json" if args.model != "." else "tokenizer.json"
|
| 31 |
+
if not tokenizer_path.startswith(("http://", "https://")) and "/" in args.model and not __import__("os").path.exists(tokenizer_path):
|
| 32 |
+
from huggingface_hub import hf_hub_download
|
| 33 |
+
tokenizer_path = hf_hub_download(args.model, "tokenizer.json")
|
| 34 |
+
tokenizer = Tokenizer.from_file(tokenizer_path)
|
| 35 |
+
eos_id = tokenizer.token_to_id("<eos>")
|
| 36 |
+
token_ids = tokenizer.encode(args.prompt).ids
|
| 37 |
+
|
| 38 |
+
generator = torch.Generator(device=device).manual_seed(42)
|
| 39 |
+
with torch.inference_mode():
|
| 40 |
+
for _ in range(args.max_new_tokens):
|
| 41 |
+
context = token_ids[-model.config.context_length :]
|
| 42 |
+
input_ids = torch.tensor([context], device=device, dtype=torch.long)
|
| 43 |
+
logits = model(input_ids=input_ids).logits[0, -1].float()
|
| 44 |
+
k = min(args.top_k, logits.numel())
|
| 45 |
+
values, indexes = torch.topk(logits, k=k)
|
| 46 |
+
probabilities = torch.softmax(values / args.temperature, dim=-1)
|
| 47 |
+
next_id = int(indexes[torch.multinomial(probabilities, 1, generator=generator)].item())
|
| 48 |
+
if next_id == eos_id:
|
| 49 |
+
break
|
| 50 |
+
token_ids.append(next_id)
|
| 51 |
+
|
| 52 |
+
print(tokenizer.decode(token_ids, skip_special_tokens=True))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
main()
|
generation_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 0,
|
| 4 |
+
"eos_token_id": 1,
|
| 5 |
+
"pad_token_id": 1,
|
| 6 |
+
"do_sample": true,
|
| 7 |
+
"temperature": 0.8,
|
| 8 |
+
"top_k": 40,
|
| 9 |
+
"max_new_tokens": 128
|
| 10 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5bc6c9dfa6cda42b96a46f5fa5a76c51e7088214a69c88bc33d749e2b9e9e8f2
|
| 3 |
+
size 48781128
|
modeling_fineweb.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Decoder-only Transformer used by the educational FineWeb model family."""
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
+
import transformers
|
| 7 |
+
from transformers import PreTrainedModel
|
| 8 |
+
from transformers.generation import GenerationMixin
|
| 9 |
+
from transformers.modeling_outputs import CausalLMOutput
|
| 10 |
+
|
| 11 |
+
from .configuration_fineweb import FineWebConfig
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class RMSNorm(nn.Module):
|
| 15 |
+
def __init__(self, width, eps=1e-6):
|
| 16 |
+
super().__init__()
|
| 17 |
+
self.weight = nn.Parameter(torch.ones(width))
|
| 18 |
+
self.eps = eps
|
| 19 |
+
|
| 20 |
+
def forward(self, x):
|
| 21 |
+
scale = torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps)
|
| 22 |
+
return x * scale * self.weight
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def apply_rope(x, cos, sin):
|
| 26 |
+
even = x[..., 0::2]
|
| 27 |
+
odd = x[..., 1::2]
|
| 28 |
+
rotated = torch.stack((even * cos - odd * sin, even * sin + odd * cos), dim=-1)
|
| 29 |
+
return rotated.flatten(start_dim=-2)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class CausalSelfAttention(nn.Module):
|
| 33 |
+
def __init__(self, width, heads, context_length):
|
| 34 |
+
super().__init__()
|
| 35 |
+
if width % heads:
|
| 36 |
+
raise ValueError("d_model must be divisible by n_heads")
|
| 37 |
+
self.heads = heads
|
| 38 |
+
self.head_dim = width // heads
|
| 39 |
+
self.context_length = context_length
|
| 40 |
+
self.qkv = nn.Linear(width, 3 * width, bias=False)
|
| 41 |
+
self.output = nn.Linear(width, width, bias=False)
|
| 42 |
+
|
| 43 |
+
def forward(self, x):
|
| 44 |
+
batch, tokens, width = x.shape
|
| 45 |
+
if tokens > self.context_length:
|
| 46 |
+
raise ValueError("Input exceeds configured context length")
|
| 47 |
+
qkv = self.qkv(x).view(batch, tokens, 3, self.heads, self.head_dim)
|
| 48 |
+
query, key, value = qkv.unbind(dim=2)
|
| 49 |
+
query = query.transpose(1, 2)
|
| 50 |
+
key = key.transpose(1, 2)
|
| 51 |
+
value = value.transpose(1, 2)
|
| 52 |
+
inv_frequency = 1.0 / (
|
| 53 |
+
10000
|
| 54 |
+
** (
|
| 55 |
+
torch.arange(0, self.head_dim, 2, device=x.device).float()
|
| 56 |
+
/ self.head_dim
|
| 57 |
+
)
|
| 58 |
+
)
|
| 59 |
+
frequencies = torch.outer(
|
| 60 |
+
torch.arange(tokens, device=x.device, dtype=torch.float), inv_frequency
|
| 61 |
+
)
|
| 62 |
+
cos = frequencies.cos().to(dtype=query.dtype)[None, None, :, :]
|
| 63 |
+
sin = frequencies.sin().to(dtype=query.dtype)[None, None, :, :]
|
| 64 |
+
query = apply_rope(query, cos, sin)
|
| 65 |
+
key = apply_rope(key, cos, sin)
|
| 66 |
+
attended = F.scaled_dot_product_attention(query, key, value, is_causal=True)
|
| 67 |
+
attended = attended.transpose(1, 2).contiguous().view(batch, tokens, width)
|
| 68 |
+
return self.output(attended)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class SwiGLU(nn.Module):
|
| 72 |
+
def __init__(self, width, hidden):
|
| 73 |
+
super().__init__()
|
| 74 |
+
self.gate_and_up = nn.Linear(width, 2 * hidden, bias=False)
|
| 75 |
+
self.down = nn.Linear(hidden, width, bias=False)
|
| 76 |
+
|
| 77 |
+
def forward(self, x):
|
| 78 |
+
gate, up = self.gate_and_up(x).chunk(2, dim=-1)
|
| 79 |
+
return self.down(F.silu(gate) * up)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
class TransformerBlock(nn.Module):
|
| 83 |
+
def __init__(self, config):
|
| 84 |
+
super().__init__()
|
| 85 |
+
self.attention_norm = RMSNorm(config.d_model, config.rms_norm_eps)
|
| 86 |
+
self.attention = CausalSelfAttention(
|
| 87 |
+
config.d_model, config.n_heads, config.context_length
|
| 88 |
+
)
|
| 89 |
+
self.mlp_norm = RMSNorm(config.d_model, config.rms_norm_eps)
|
| 90 |
+
self.mlp = SwiGLU(config.d_model, config.mlp_hidden)
|
| 91 |
+
|
| 92 |
+
def forward(self, x):
|
| 93 |
+
x = x + self.attention(self.attention_norm(x))
|
| 94 |
+
return x + self.mlp(self.mlp_norm(x))
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class FineWebForCausalLM(PreTrainedModel, GenerationMixin):
|
| 98 |
+
model_type = "fineweb_decoder"
|
| 99 |
+
config_class = FineWebConfig
|
| 100 |
+
base_model_prefix = "fineweb"
|
| 101 |
+
main_input_name = "input_ids"
|
| 102 |
+
_tied_weights_keys = (
|
| 103 |
+
{"lm_head.weight": "embedding.weight"}
|
| 104 |
+
if int(transformers.__version__.split(".", 1)[0]) >= 5
|
| 105 |
+
else ["lm_head.weight"]
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
def __init__(self, config):
|
| 109 |
+
super().__init__(config)
|
| 110 |
+
self.embedding = nn.Embedding(config.vocab_size, config.d_model)
|
| 111 |
+
self.blocks = nn.ModuleList(
|
| 112 |
+
[TransformerBlock(config) for _ in range(config.n_layers)]
|
| 113 |
+
)
|
| 114 |
+
self.final_norm = RMSNorm(config.d_model, config.rms_norm_eps)
|
| 115 |
+
self.lm_head = nn.Linear(config.d_model, config.vocab_size, bias=False)
|
| 116 |
+
self.post_init()
|
| 117 |
+
|
| 118 |
+
def _init_weights(self, module):
|
| 119 |
+
if isinstance(module, (nn.Linear, nn.Embedding)):
|
| 120 |
+
nn.init.normal_(module.weight, mean=0.0, std=0.02)
|
| 121 |
+
|
| 122 |
+
def get_input_embeddings(self):
|
| 123 |
+
return self.embedding
|
| 124 |
+
|
| 125 |
+
def set_input_embeddings(self, value):
|
| 126 |
+
self.embedding = value
|
| 127 |
+
|
| 128 |
+
def get_output_embeddings(self):
|
| 129 |
+
return self.lm_head
|
| 130 |
+
|
| 131 |
+
def set_output_embeddings(self, value):
|
| 132 |
+
self.lm_head = value
|
| 133 |
+
|
| 134 |
+
def forward(self, input_ids=None, labels=None, return_dict=True, **kwargs):
|
| 135 |
+
if input_ids is None:
|
| 136 |
+
raise ValueError("input_ids is required")
|
| 137 |
+
input_ids = input_ids[:, -self.config.context_length :]
|
| 138 |
+
x = self.embedding(input_ids)
|
| 139 |
+
for block in self.blocks:
|
| 140 |
+
x = block(x)
|
| 141 |
+
logits = self.lm_head(self.final_norm(x))
|
| 142 |
+
loss = None
|
| 143 |
+
if labels is not None:
|
| 144 |
+
labels = labels[:, -input_ids.size(1) :]
|
| 145 |
+
loss = F.cross_entropy(
|
| 146 |
+
logits[:, :-1].contiguous().view(-1, self.config.vocab_size),
|
| 147 |
+
labels[:, 1:].contiguous().view(-1),
|
| 148 |
+
ignore_index=-100,
|
| 149 |
+
)
|
| 150 |
+
if not return_dict:
|
| 151 |
+
return (loss, logits) if loss is not None else (logits,)
|
| 152 |
+
return CausalLMOutput(loss=loss, logits=logits)
|
| 153 |
+
|
| 154 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 155 |
+
return {"input_ids": input_ids[:, -self.config.context_length :], "use_cache": False}
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.1
|
| 2 |
+
transformers>=4.46,<6
|
| 3 |
+
tokenizers>=0.20
|
| 4 |
+
safetensors>=0.4
|
| 5 |
+
huggingface_hub>=0.26
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<bos>",
|
| 4 |
+
"eos_token": "<eos>",
|
| 5 |
+
"model_max_length": 1024,
|
| 6 |
+
"pad_token": "<eos>",
|
| 7 |
+
"tokenizer_class": "TokenizersBackend",
|
| 8 |
+
"unk_token": "<unk>"
|
| 9 |
+
}
|