yujiepan commited on
Commit
e9af3b7
1 Parent(s): dbcf1d1

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +61 -0
README.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text-generation
3
+ inference: true
4
+ widget:
5
+ - text: 'Hello!'
6
+ example_title: Hello world
7
+ group: Python
8
+ library_name: transformers
9
+ ---
10
+
11
+ This model is randomly initialized, using the config from [state-spaces/mamba-2.8b-hf](https://huggingface.co/state-spaces/mamba-2.8b-hf/blob/main/config.json) but with smaller size.
12
+ Note the model is in float16.
13
+
14
+ Codes:
15
+ ```python
16
+ import transformers
17
+ import torch
18
+ import os
19
+ from huggingface_hub import create_repo, upload_folder
20
+
21
+ source_model_id = 'state-spaces/mamba-2.8b-hf'
22
+ tiny_random_name = 'mamba-tiny-random'
23
+ save_path = f'/tmp/yujiepan/{tiny_random_name}'
24
+ repo_id = f'yujiepan/{tiny_random_name}'
25
+
26
+ config = transformers.AutoConfig.from_pretrained(
27
+ source_model_id, trust_remote_code=True)
28
+ config.hidden_size = 4
29
+ config.intermediate_size = 6
30
+ # config.num_attention_heads = 4
31
+ # config.num_key_value_heads = 2
32
+ config.num_hidden_layers = 2
33
+ config.n_layer = 2
34
+
35
+ config.torch_dtype = torch.float16
36
+
37
+ model = transformers.AutoModelForCausalLM.from_config(
38
+ config, trust_remote_code=True, torch_dtype=torch.float16)
39
+ model = model.half()
40
+
41
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
42
+ source_model_id, trust_remote_code=True)
43
+
44
+ result = transformers.pipelines.pipeline(
45
+ 'text-generation',
46
+ model=model, tokenizer=tokenizer,
47
+ device=0,
48
+ max_new_tokens=16,
49
+ )('Hello')
50
+ print(result)
51
+ # model = model.cuda()
52
+ # response, history = model.chat(tokenizer, "Hi", history=[], max_length=32)
53
+ # print(response)
54
+
55
+ model.save_pretrained(save_path)
56
+ tokenizer.save_pretrained(save_path)
57
+
58
+ os.system(f'ls -alh {save_path}')
59
+ create_repo(repo_id, exist_ok=True)
60
+ upload_folder(repo_id=repo_id, folder_path=save_path)
61
+ ```