tiny random model
Browse files- config.json +33 -0
- m2m-make-tiny-model.py +56 -0
- pytorch_model.bin +3 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- vocab.json +0 -0
config.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"activation_dropout": 0.0,
|
3 |
+
"activation_function": "relu",
|
4 |
+
"architectures": [
|
5 |
+
"M2M100ForConditionalGeneration"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"bos_token_id": 0,
|
9 |
+
"d_model": 16,
|
10 |
+
"decoder_attention_heads": 4,
|
11 |
+
"decoder_ffn_dim": 4,
|
12 |
+
"decoder_layerdrop": 0.05,
|
13 |
+
"decoder_layers": 2,
|
14 |
+
"decoder_start_token_id": 2,
|
15 |
+
"dropout": 0.1,
|
16 |
+
"encoder_attention_heads": 4,
|
17 |
+
"encoder_ffn_dim": 4,
|
18 |
+
"encoder_layerdrop": 0.05,
|
19 |
+
"encoder_layers": 2,
|
20 |
+
"eos_token_id": 2,
|
21 |
+
"gradient_checkpointing": false,
|
22 |
+
"init_std": 0.02,
|
23 |
+
"is_encoder_decoder": true,
|
24 |
+
"max_position_embeddings": 512,
|
25 |
+
"model_type": "m2m_100",
|
26 |
+
"num_hidden_layers": 2,
|
27 |
+
"pad_token_id": 1,
|
28 |
+
"scale_embedding": true,
|
29 |
+
"torch_dtype": "float16",
|
30 |
+
"transformers_version": "4.19.0.dev0",
|
31 |
+
"use_cache": true,
|
32 |
+
"vocab_size": 128112
|
33 |
+
}
|
m2m-make-tiny-model.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# coding: utf-8
|
3 |
+
# Copyright 2020 The HuggingFace Team. All rights reserved.
|
4 |
+
#
|
5 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6 |
+
# you may not use this file except in compliance with the License.
|
7 |
+
# You may obtain a copy of the License at
|
8 |
+
#
|
9 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10 |
+
#
|
11 |
+
# Unless required by applicable law or agreed to in writing, software
|
12 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 |
+
# See the License for the specific language governing permissions and
|
15 |
+
# limitations under the License.
|
16 |
+
|
17 |
+
# This script creates a super tiny model that is useful inside tests, when we just want to test that
|
18 |
+
# the machinery works, without needing to the check the quality of the outcomes.
|
19 |
+
#
|
20 |
+
# This version is derived from https://huggingface.co/hf-internal-testing/tiny-random-m2m_100
|
21 |
+
# but with max_position_embeddings=512 so that we don't need to recreate pos embeddings during forward
|
22 |
+
#
|
23 |
+
# It will be used then as "stas/tiny-m2m_100"
|
24 |
+
|
25 |
+
# Build
|
26 |
+
from transformers import M2M100Tokenizer, M2M100Config, M2M100ForConditionalGeneration
|
27 |
+
|
28 |
+
mname = "hf-internal-testing/tiny-random-m2m_100"
|
29 |
+
|
30 |
+
tokenizer = M2M100Tokenizer.from_pretrained(mname)
|
31 |
+
# get the correct vocab sizes, etc. from the master model
|
32 |
+
config = M2M100Config.from_pretrained(mname)
|
33 |
+
# replicate the existing tiny model but we need longer max_position_embeddings
|
34 |
+
config.update(dict(
|
35 |
+
max_position_embeddings=512,
|
36 |
+
))
|
37 |
+
|
38 |
+
tiny_model = M2M100ForConditionalGeneration(config)
|
39 |
+
print(f"num of params {tiny_model.num_parameters()}")
|
40 |
+
|
41 |
+
# Test
|
42 |
+
model_inputs = tokenizer("Making tiny model", return_tensors="pt")
|
43 |
+
gen_tokens = tiny_model.generate(**model_inputs, forced_bos_token_id=tokenizer.get_lang_id("fr"))
|
44 |
+
print(tokenizer.batch_decode(gen_tokens, skip_special_tokens=True))
|
45 |
+
#
|
46 |
+
|
47 |
+
# Save
|
48 |
+
mname_tiny = "tiny-m2m_100"
|
49 |
+
tiny_model.half() # makes it smaller
|
50 |
+
tiny_model.save_pretrained(mname_tiny)
|
51 |
+
tokenizer.save_pretrained(mname_tiny)
|
52 |
+
|
53 |
+
print(f"Generated {mname_tiny}")
|
54 |
+
|
55 |
+
# Upload
|
56 |
+
# transformers-cli upload tiny-m2m_100
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:62e77e2232830ad7d9bcf9bdbd1d447aa0bdaa3e0ed794b4ebda0d094c95e49e
|
3 |
+
size 4140698
|
sentencepiece.bpe.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d8f7c76ed2a5e0822be39f0a4f95a55eb19c78f4593ce609e2edbc2aea4d380a
|
3 |
+
size 2423393
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "additional_special_tokens": ["__af__", "__am__", "__ar__", "__ast__", "__az__", "__ba__", "__be__", "__bg__", "__bn__", "__br__", "__bs__", "__ca__", "__ceb__", "__cs__", "__cy__", "__da__", "__de__", "__el__", "__en__", "__es__", "__et__", "__fa__", "__ff__", "__fi__", "__fr__", "__fy__", "__ga__", "__gd__", "__gl__", "__gu__", "__ha__", "__he__", "__hi__", "__hr__", "__ht__", "__hu__", "__hy__", "__id__", "__ig__", "__ilo__", "__is__", "__it__", "__ja__", "__jv__", "__ka__", "__kk__", "__km__", "__kn__", "__ko__", "__lb__", "__lg__", "__ln__", "__lo__", "__lt__", "__lv__", "__mg__", "__mk__", "__ml__", "__mn__", "__mr__", "__ms__", "__my__", "__ne__", "__nl__", "__no__", "__ns__", "__oc__", "__or__", "__pa__", "__pl__", "__ps__", "__pt__", "__ro__", "__ru__", "__sd__", "__si__", "__sk__", "__sl__", "__so__", "__sq__", "__sr__", "__ss__", "__su__", "__sv__", "__sw__", "__ta__", "__th__", "__tl__", "__tn__", "__tr__", "__uk__", "__ur__", "__uz__", "__vi__", "__wo__", "__xh__", "__yi__", "__yo__", "__zh__", "__zu__"]}
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"src_lang": null, "tgt_lang": null, "bos_token": "<s>", "eos_token": "</s>", "sep_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>", "language_codes": "m2m100", "sp_model_kwargs": {}, "num_madeup_words": 8, "special_tokens_map_file": "m2m_100_1.2B_v2/special_tokens_map.json", "tokenizer_file": null, "name_or_path": "hf-internal-testing/tiny-random-m2m_100", "model_max_length": 1024, "additional_special_tokens": ["__af__", "__am__", "__ar__", "__ast__", "__az__", "__ba__", "__be__", "__bg__", "__bn__", "__br__", "__bs__", "__ca__", "__ceb__", "__cs__", "__cy__", "__da__", "__de__", "__el__", "__en__", "__es__", "__et__", "__fa__", "__ff__", "__fi__", "__fr__", "__fy__", "__ga__", "__gd__", "__gl__", "__gu__", "__ha__", "__he__", "__hi__", "__hr__", "__ht__", "__hu__", "__hy__", "__id__", "__ig__", "__ilo__", "__is__", "__it__", "__ja__", "__jv__", "__ka__", "__kk__", "__km__", "__kn__", "__ko__", "__lb__", "__lg__", "__ln__", "__lo__", "__lt__", "__lv__", "__mg__", "__mk__", "__ml__", "__mn__", "__mr__", "__ms__", "__my__", "__ne__", "__nl__", "__no__", "__ns__", "__oc__", "__or__", "__pa__", "__pl__", "__ps__", "__pt__", "__ro__", "__ru__", "__sd__", "__si__", "__sk__", "__sl__", "__so__", "__sq__", "__sr__", "__ss__", "__su__", "__sv__", "__sw__", "__ta__", "__th__", "__tl__", "__tn__", "__tr__", "__uk__", "__ur__", "__uz__", "__vi__", "__wo__", "__xh__", "__yi__", "__yo__", "__zh__", "__zu__"], "tokenizer_class": "M2M100Tokenizer"}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|