Upload folder using huggingface_hub
Browse files
README.md
CHANGED
@@ -8,7 +8,7 @@ widget:
|
|
8 |
library_name: transformers
|
9 |
---
|
10 |
|
11 |
-
This model is randomly initialized, using the config from [
|
12 |
Note the model is in float16.
|
13 |
|
14 |
Codes:
|
@@ -18,36 +18,42 @@ import torch
|
|
18 |
import os
|
19 |
from huggingface_hub import create_repo, upload_folder
|
20 |
|
21 |
-
source_model_id = '
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
config = transformers.AutoConfig.from_pretrained(
|
26 |
source_model_id, trust_remote_code=True)
|
27 |
config.hidden_size = 4
|
28 |
config.intermediate_size = 8
|
29 |
-
config.num_attention_heads =
|
30 |
-
config.
|
31 |
config.num_hidden_layers = 2
|
32 |
-
config.num_key_value_heads = 2
|
33 |
-
config.num_local_experts = 8
|
34 |
config.torch_dtype = torch.float16
|
35 |
|
36 |
model = transformers.AutoModelForCausalLM.from_config(
|
37 |
-
config, trust_remote_code=True)
|
38 |
model = model.half()
|
39 |
-
model.save_pretrained(save_path)
|
40 |
|
41 |
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
42 |
source_model_id, trust_remote_code=True)
|
43 |
-
tokenizer.save_pretrained(save_path)
|
44 |
|
45 |
result = transformers.pipelines.pipeline(
|
46 |
'text-generation',
|
47 |
-
model=model
|
|
|
|
|
|
|
48 |
print(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
os.system(f'ls -alh {save_path}')
|
51 |
create_repo(repo_id, exist_ok=True)
|
52 |
upload_folder(repo_id=repo_id, folder_path=save_path)
|
53 |
-
```
|
|
|
8 |
library_name: transformers
|
9 |
---
|
10 |
|
11 |
+
This model is randomly initialized, using the config from [hpcai-tech/grok-1](https://huggingface.co/hpcai-tech/grok-1/blob/main/config.json) but with smaller size.
|
12 |
Note the model is in float16.
|
13 |
|
14 |
Codes:
|
|
|
18 |
import os
|
19 |
from huggingface_hub import create_repo, upload_folder
|
20 |
|
21 |
+
source_model_id = 'hpcai-tech/grok-1'
|
22 |
+
tiny_random_name = 'grok-1-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 = 8
|
30 |
+
config.num_attention_heads = 2
|
31 |
+
config.num_key_value_heads = 1
|
32 |
config.num_hidden_layers = 2
|
|
|
|
|
33 |
config.torch_dtype = torch.float16
|
34 |
|
35 |
model = transformers.AutoModelForCausalLM.from_config(
|
36 |
+
config, trust_remote_code=True, torch_dtype=torch.float16)
|
37 |
model = model.half()
|
|
|
38 |
|
39 |
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
40 |
source_model_id, trust_remote_code=True)
|
|
|
41 |
|
42 |
result = transformers.pipelines.pipeline(
|
43 |
'text-generation',
|
44 |
+
model=model, tokenizer=tokenizer,
|
45 |
+
device=0,
|
46 |
+
max_new_tokens=16,
|
47 |
+
)('Hello')
|
48 |
print(result)
|
49 |
+
# model = model.cuda()
|
50 |
+
# response, history = model.chat(tokenizer, "Hi", history=[], max_length=32)
|
51 |
+
# print(response)
|
52 |
+
|
53 |
+
model.save_pretrained(save_path)
|
54 |
+
tokenizer.save_pretrained(save_path)
|
55 |
|
56 |
os.system(f'ls -alh {save_path}')
|
57 |
create_repo(repo_id, exist_ok=True)
|
58 |
upload_folder(repo_id=repo_id, folder_path=save_path)
|
59 |
+
```
|