-
Notifications
You must be signed in to change notification settings - Fork 34.1k
[WIP] Add GeoV model #22403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add GeoV model #22403
Changes from 16 commits
414b6d3
f7de635
dd81ba7
9f7d0fc
b179326
9ad19e8
ef0c211
1d1f4c6
504c5d7
f7029cf
6e9e66e
08e18a8
b775b10
119075c
c78f65b
2b6f102
1fdc965
6a91ed8
e108c53
f32d35e
f09bb94
afe4c38
7f097bd
c8bfa31
e936421
8bf1222
c6d150c
850910b
810ca39
2f97d45
8ed7dd7
9305c86
3bb636d
3ad28db
c51af06
cfbdfe5
c30251a
8936db6
3e2bc07
17c32bd
a62cc58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <!--Copyright 2023 The Better Planet Investments, labml.ai and The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
| --> | ||
|
|
||
| # GeoV | ||
|
|
||
| ## Overview | ||
|
|
||
| The GeoV model was designed by Georges Harik and uses [Rotary Positional Embeddings with Relative distances (RoPER)](http://research.labml.ai/RoPER.html) by [Georges Hark](https://twitter.com/ghark) and [Varuna Jayasiri](https://twitter.com/vpj). | ||
|
|
||
| [RoPER](http://research.labml.ai/RoPER.html), in addition to using relative positions in the attention score calculation by RoPE embeddings, adds relative positional information explicitly to value embeddings. Specifically, it incorporates the relative positions of the tokens paid attention to. RoPER has given better performance in some algorithmic tasks, and seems comparable to RoPE in language modeling. | ||
|
|
||
| The GeoV tokenizer uses [SentencePiece](https://github.com/google/sentencepiece) [unigram language model](https://arxiv.org/abs/1804.10959) and tokenizes symbols, digits and new line characters separately, in order to achieve better performance on mathematical content and code. | ||
|
|
||
| This model was contributed by [gharik](https://huggingface.co/gharik) and [vpj](https://huggingface.co/vpj). | ||
|
|
||
| We have shared 9B parameter pre-trained model at [GeoV/GeoV-9b](https://huggingface.co/GeoV/GeoV-9b). | ||
| We plan to release checkpoints around every 20b tokens trained from here until around 300b tokens. | ||
| We will also train smaller and larger versions. Our aim is to have broadly available smaller and larger models. | ||
|
|
||
| ## Generation | ||
|
|
||
| The `generate()` method can be used to generate text using GeoV model. | ||
|
|
||
| ```python | ||
| >>> from transformers import GeoVForCausalLM, GeoVTokenizer | ||
|
|
||
| >>> model = GeoVForCausalLM.from_pretrained("GeoV/GeoV-9b") | ||
| >>> tokenizer = GeoVTokenizer.from_pretrained("GeoV/GeoV-9b") | ||
|
|
||
| >>> prompt = "In mathematics, topology is the study of" | ||
|
|
||
| >>> input_ids = tokenizer(prompt, return_tensors="pt").input_ids | ||
|
|
||
| >>> gen_tokens = model.generate( | ||
| ... input_ids, | ||
| ... do_sample=True, | ||
| ... temperature=0.9, | ||
| ... max_length=100, | ||
| ... ) | ||
| >>> gen_text = tokenizer.batch_decode(gen_tokens)[0] | ||
| ``` | ||
|
|
||
| ## GeoVConfig | ||
|
|
||
| [[autodoc]] GeoVConfig | ||
|
|
||
| ## GeoVTokenizer | ||
|
|
||
| [[autodoc]] GeoVTokenizer | ||
|
|
||
| ## GeoVModel | ||
|
|
||
| [[autodoc]] GeoVModel | ||
| - forward | ||
|
|
||
| ## GeoVForCausalLM | ||
|
|
||
| [[autodoc]] GeoVForCausalLM | ||
| - forward |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ | |
| gpt2, | ||
| gpt_neo, | ||
| gpt_neox, | ||
| geov, | ||
| gpt_neox_japanese, | ||
| gpt_sw3, | ||
| gptj, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright 2023 The HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available | ||
| from ...utils import OptionalDependencyNotAvailable | ||
|
|
||
|
|
||
| _import_structure = {"configuration_geov": ["GEOV_PRETRAINED_CONFIG_ARCHIVE_MAP", "GeoVConfig"]} | ||
|
|
||
| try: | ||
| if not is_tokenizers_available(): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| pass | ||
| else: | ||
| _import_structure["tokenization_geov"] = ["GeoVTokenizer"] | ||
|
|
||
| try: | ||
| if not is_torch_available(): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| pass | ||
| else: | ||
| _import_structure["modeling_geov"] = [ | ||
| "GEOV_PRETRAINED_MODEL_ARCHIVE_LIST", | ||
| "GeoVForCausalLM", | ||
| "GeoVLayer", | ||
| "GeoVModel", | ||
| "GeoVPreTrainedModel", | ||
| ] | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_geov import GEOV_PRETRAINED_CONFIG_ARCHIVE_MAP, GeoVConfig | ||
|
|
||
| try: | ||
| if not is_tokenizers_available(): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| pass | ||
| else: | ||
| from .tokenization_geov import GeoVTokenizer | ||
|
|
||
| try: | ||
| if not is_torch_available(): | ||
| raise OptionalDependencyNotAvailable() | ||
| except OptionalDependencyNotAvailable: | ||
| pass | ||
| else: | ||
| from .modeling_geov import ( | ||
| GEOV_PRETRAINED_MODEL_ARCHIVE_LIST, | ||
| GeoVForCausalLM, | ||
| GeoVLayer, | ||
| GeoVModel, | ||
| GeoVPreTrainedModel, | ||
| ) | ||
|
|
||
|
|
||
| else: | ||
| import sys | ||
|
|
||
| sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__) |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This model should be almost entirely the same as
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why rename GeoV to Geov? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2023 Better Planet Investments and labml.ai team. ALl rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ GeoV model configuration""" | ||
|
|
||
| from ...configuration_utils import PretrainedConfig | ||
| from ...utils import logging | ||
|
|
||
|
|
||
| logger = logging.get_logger(__name__) | ||
|
|
||
| GEOV_PRETRAINED_CONFIG_ARCHIVE_MAP = { | ||
| "GeoV/GeoV-9b": "https://huggingface.co/GeoV/GeoV-9b/resolve/main/config.json", | ||
| } | ||
|
|
||
|
|
||
| class GeoVConfig(PretrainedConfig): | ||
| r""" | ||
| This is the configuration class to store the configuration of a [`GeoVModel`]. It is used to instantiate an | ||
| GeoV model according to the specified arguments, defining the model architecture. Instantiating a configuration | ||
|
vpj marked this conversation as resolved.
Outdated
|
||
| with the defaults will yield a similar configuration to that of the GeoV | ||
| [GeoV/GeoV-9b](https://huggingface.co/GeoV/GeoV-9b) architecture. | ||
|
|
||
| Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the | ||
| documentation from [`PretrainedConfig`] for more information. | ||
|
|
||
|
|
||
| Args: | ||
| vocab_size (`int`, *optional*, defaults to 50432): | ||
| Vocabulary size of the GeoV model. Defines the number of different tokens that can be represented by the | ||
|
vpj marked this conversation as resolved.
Outdated
|
||
| `inputs_ids` passed when calling [`GeoVModel`]. | ||
| hidden_size (`int`, *optional*, defaults to 6144): | ||
| Dimension of the encoder layers and the pooler layer. | ||
| num_hidden_layers (`int`, *optional*, defaults to 44): | ||
| Number of hidden layers in the Transformer encoder. | ||
| num_attention_heads (`int`, *optional*, defaults to 64): | ||
| Number of attention heads for each attention layer in the Transformer encoder. | ||
| intermediate_size (`int`, *optional*, defaults to 24576): | ||
| Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder. | ||
| rotary_emb_base (`int`, *optional*, defaults to 10000) | ||
| base for computing rotary embeddings frequency | ||
| max_position_embeddings (`int`, *optional*, defaults to 2048): | ||
| The maximum sequence length that this model might ever be used with. Typically set this to something large | ||
| just in case (e.g., 512 or 1024 or 2048). | ||
| layer_norm_eps (`float`, *optional*, defaults to 1e-4): | ||
| The epsilon used by the layer normalization layers. | ||
| use_cache (`bool`, *optional*, defaults to `True`): | ||
| Whether or not the model should return the last key/values attentions (not used by all models). Only | ||
| relevant if `config.is_decoder=True`. | ||
| use_extra_biases_ffn (`bool`, *optional*, defaults to `False`): | ||
| Whether or not to have extra bias parameters in the final layer of FFN modules. | ||
| Example: | ||
|
|
||
| ```python | ||
| >>> from transformers import GeoVConfig, GeoVModel | ||
|
|
||
| >>> # Initializing a GeoV configuration | ||
| >>> configuration = GeoVConfig() | ||
|
|
||
| >>> # Initializing a model (with random weights) from the configuration | ||
| >>> model = GeoVModel(configuration) # doctest: +SKIP | ||
|
|
||
| >>> # Accessing the model configuration | ||
| >>> configuration = model.config # doctest: +SKIP | ||
| ```""" | ||
| model_type = "geov" | ||
|
|
||
| def __init__( | ||
| self, | ||
| vocab_size=65536, | ||
| hidden_size=1024 * 5, | ||
| num_hidden_layers=32, | ||
| num_attention_heads=40, | ||
| intermediate_size=1024 * 5 * 4, | ||
| layer_norm_eps=1e-4, | ||
| rotary_emb_base=10000, | ||
| max_position_embeddings=2049, | ||
|
vpj marked this conversation as resolved.
Outdated
|
||
| use_extra_biases_ffn=False, | ||
| use_cache=True, | ||
| bos_token_id=0, | ||
| eos_token_id=2, | ||
| tie_word_embeddings=False, | ||
| **kwargs, | ||
| ): | ||
| super().__init__( | ||
| bos_token_id=bos_token_id, eos_token_id=eos_token_id, tie_word_embeddings=tie_word_embeddings, **kwargs | ||
| ) | ||
| self.vocab_size = vocab_size | ||
| self.max_position_embeddings = max_position_embeddings | ||
| self.hidden_size = hidden_size | ||
| self.num_hidden_layers = num_hidden_layers | ||
| self.num_attention_heads = num_attention_heads | ||
| self.intermediate_size = intermediate_size | ||
| self.rotary_emb_base = rotary_emb_base | ||
| self.use_cache = use_cache | ||
| self.layer_norm_eps = layer_norm_eps | ||
| self.use_extra_biases_ffn = use_extra_biases_ffn | ||
Uh oh!
There was an error while loading. Please reload this page.