patrickvonplaten commited on
Commit
7ebead3
1 Parent(s): 7a9344a
model/restored.pt CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:527a6e3e1b2446d6e9ecf436db8066430ef752935c1fd1ba9fa66f3cd8e307cd
3
- size 13317196205
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5c0b91d14be61699051322a6ebd3eff229701716f03c458816a468a1bf86ee1
3
+ size 13317196599
model/special_tokens_map.json CHANGED
@@ -1 +1,23 @@
1
- {"bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "unk_token": {
17
+ "content": "<|endoftext|>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ }
23
+ }
model/tokenizer_config.json CHANGED
@@ -1 +1,31 @@
1
- {"errors": "replace", "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "bos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "add_prefix_space": false, "tokenizer_class": "GPT2Tokenizer"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "bos_token": {
5
+ "__type": "AddedToken",
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "eos_token": {
13
+ "__type": "AddedToken",
14
+ "content": "<|endoftext|>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "errors": "replace",
21
+ "pad_token": null,
22
+ "tokenizer_class": "GPT2Tokenizer",
23
+ "unk_token": {
24
+ "__type": "AddedToken",
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": true,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
model/vocab.json CHANGED
The diff for this file is too large to render. See raw diff
 
run_model.py CHANGED
@@ -1,23 +1,14 @@
1
  #!/usr/bin/env python3
2
  import os
3
  from transformers import AutoTokenizer, GPT2Tokenizer
4
- from megatron.initialize import initialize_megatron
5
  from metaseq import checkpoint_utils
6
  from transformers import OPTForCausalLM
7
  import torch
8
 
9
  path = "./model"
 
10
 
11
- # just need to initialize args with something,
12
- # => doesn't need to correspond to the "correct" architecture for this checkpoint
13
- initialize_megatron(args_defaults={
14
- "micro_batch_size": 1,
15
- "num_layers": 12,
16
- "hidden_size": 768,
17
- "num_attention_heads": 12,
18
- "max_position_embeddings": 2048,
19
- "encoder_seq_length": 2048
20
- })
21
 
22
  vocab_file = os.path.join(path, "gpt2-vocab.json")
23
  merges_file = os.path.join(path, "gpt2-merges.txt")
@@ -34,16 +25,15 @@ checkpoint = checkpoint_utils.load_model_ensemble_and_task(
34
  )
35
 
36
  model = checkpoint[0][0].eval()
37
- model = model.to("cuda:0").half()
38
-
39
- hf_model = OPTForCausalLM.from_pretrained("../opt-6.7b").to("cuda:1").half()
40
 
 
41
 
42
  # forward passes
43
  def single_batch_forward_logits(prompts):
44
  input_ids = tokenizer(prompts, return_tensors="pt").input_ids
45
  input_ids = torch.cat([torch.tensor([[0]]), input_ids], dim=-1)
46
- input_ids = input_ids.to("cuda:0")
47
  with torch.no_grad():
48
  logits = model(input_ids)[0]
49
  return logits
@@ -52,7 +42,7 @@ def single_batch_forward_logits(prompts):
52
  def forward_hf(prompts):
53
  input_ids = tokenizer(prompts, return_tensors="pt").input_ids
54
  input_ids = torch.cat([torch.tensor([[0]]), input_ids], dim=-1)
55
- input_ids = input_ids.to("cuda:1")
56
  with torch.no_grad():
57
  logits = hf_model(input_ids)[0]
58
  return logits
@@ -64,11 +54,6 @@ prompts = [
64
  "Computers and mobile phones have taken",
65
  ]
66
 
67
- prompts = [
68
- "Today is a beautiful day and I want to",
69
- ]
70
-
71
- #import ipdb; ipdb.set_trace()
72
  print("Next word generation")
73
  for prompt in prompts:
74
  print("-------------")
@@ -86,4 +71,5 @@ for prompt in prompts:
86
  print(f"Next word: {next_token}")
87
  print("-------------")
88
 
89
- torch.allclose(logits_fsq.cpu(), logits.cpu(), atol=1e-3)
 
 
1
  #!/usr/bin/env python3
2
  import os
3
  from transformers import AutoTokenizer, GPT2Tokenizer
4
+ #from megatron.initialize import initialize_megatron
5
  from metaseq import checkpoint_utils
6
  from transformers import OPTForCausalLM
7
  import torch
8
 
9
  path = "./model"
10
+ hf_path = "/home/patrick/facebook/opt-6.7b"
11
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  vocab_file = os.path.join(path, "gpt2-vocab.json")
14
  merges_file = os.path.join(path, "gpt2-merges.txt")
 
25
  )
26
 
27
  model = checkpoint[0][0].eval()
28
+ model = model
 
 
29
 
30
+ hf_model = OPTForCausalLM.from_pretrained(hf_path)
31
 
32
  # forward passes
33
  def single_batch_forward_logits(prompts):
34
  input_ids = tokenizer(prompts, return_tensors="pt").input_ids
35
  input_ids = torch.cat([torch.tensor([[0]]), input_ids], dim=-1)
36
+ input_ids = input_ids
37
  with torch.no_grad():
38
  logits = model(input_ids)[0]
39
  return logits
 
42
  def forward_hf(prompts):
43
  input_ids = tokenizer(prompts, return_tensors="pt").input_ids
44
  input_ids = torch.cat([torch.tensor([[0]]), input_ids], dim=-1)
45
+ input_ids = input_ids
46
  with torch.no_grad():
47
  logits = hf_model(input_ids)[0]
48
  return logits
 
54
  "Computers and mobile phones have taken",
55
  ]
56
 
 
 
 
 
 
57
  print("Next word generation")
58
  for prompt in prompts:
59
  print("-------------")
 
71
  print(f"Next word: {next_token}")
72
  print("-------------")
73
 
74
+
75
+ print("Is equal:", torch.allclose(logits_fsq.cpu(), logits.cpu(), atol=1e-3))