myownskyW7 commited on
Commit
c06549a
1 Parent(s): 0f30f36

Upload 11 files

Browse files
config.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "_name_or_path": "chat",
3
  "architectures": [
4
  "InternLMXComposerForCausalLM"
5
  ],
@@ -17,29 +17,9 @@
17
  "initializer_range": 0.02,
18
  "intermediate_size": 11008,
19
  "intern_converted_llm": true,
20
- "internlm_lora": {
21
- "freeze": false,
22
- "learn_param": [
23
- "q",
24
- "v",
25
- "ffn"
26
- ],
27
- "lora_alpha": 256,
28
- "lora_dropout": 0.05,
29
- "lora_r": 256
30
- },
31
  "kqvo_bias": true,
32
- "lora_cfg": {
33
- "freeze": false,
34
- "learn_param": [
35
- "q",
36
- "v",
37
- "ffn"
38
- ],
39
- "lora_alpha": 256,
40
- "lora_dropout": 0.05,
41
- "lora_r": 256
42
- },
43
  "max_position_embeddings": 2048,
44
  "model_type": "InternLMXComposer",
45
  "num_attention_heads": 32,
@@ -49,8 +29,8 @@
49
  "pad_token_id": -1,
50
  "rms_norm_eps": 1e-05,
51
  "tie_word_embeddings": false,
52
- "torch_dtype": "float32",
53
- "transformers_version": "4.30.2",
54
  "use_cache": true,
55
  "vocab_size": 103168
56
  }
 
1
  {
2
+ "_name_or_path": "/mnt/petrelfs/share_data/dongxiaoyi/share_models/chat_merge/",
3
  "architectures": [
4
  "InternLMXComposerForCausalLM"
5
  ],
 
17
  "initializer_range": 0.02,
18
  "intermediate_size": 11008,
19
  "intern_converted_llm": true,
20
+ "internlm_lora": null,
 
 
 
 
 
 
 
 
 
 
21
  "kqvo_bias": true,
22
+ "lora_cfg": null,
 
 
 
 
 
 
 
 
 
 
23
  "max_position_embeddings": 2048,
24
  "model_type": "InternLMXComposer",
25
  "num_attention_heads": 32,
 
29
  "pad_token_id": -1,
30
  "rms_norm_eps": 1e-05,
31
  "tie_word_embeddings": false,
32
+ "torch_dtype": "float16",
33
+ "transformers_version": "4.33.1",
34
  "use_cache": true,
35
  "vocab_size": 103168
36
  }
modeling_InternLM.py CHANGED
@@ -6,6 +6,8 @@ import torch
6
  import torch.utils.checkpoint
7
  import torch.utils.checkpoint
8
  from einops import rearrange
 
 
9
  from torch import nn
10
  from torch.nn import CrossEntropyLoss
11
  from transformers.activations import ACT2FN
@@ -22,6 +24,8 @@ _CONFIG_FOR_DOC = "InternLMXComposerConfig"
22
 
23
 
24
  def rotary_embed(x1, x2, cos, sin, conj):
 
 
25
  x1, x2 = x1.float(), x2.float()
26
  if conj:
27
  x1, x2 = x1 * cos + x2 * sin, x1 * sin + x2 * cos
 
6
  import torch.utils.checkpoint
7
  import torch.utils.checkpoint
8
  from einops import rearrange
9
+ #import rotary_emb
10
+ #from flash_attn.layers.rotary import ApplyRotaryEmbQKV_ as LegacyApplyRotaryEmbQKV_
11
  from torch import nn
12
  from torch.nn import CrossEntropyLoss
13
  from transformers.activations import ACT2FN
 
24
 
25
 
26
  def rotary_embed(x1, x2, cos, sin, conj):
27
+ # print(x1.shape, x2.shape, cos.shape, sin.shape)
28
+ #[5, 1, 32, 64] [1, 1, 64]
29
  x1, x2 = x1.float(), x2.float()
30
  if conj:
31
  x1, x2 = x1 * cos + x2 * sin, x1 * sin + x2 * cos
modeling_InternLM_XComposer.py CHANGED
@@ -95,13 +95,15 @@ class InternLMXComposerForCausalLM(PreTrainedModel):
95
 
96
  @property
97
  def eoh(self):
98
- return self.tokenizer.decode(torch.Tensor([103027]),
99
- skip_special_tokens=True)
 
100
 
101
  @property
102
  def eoa(self):
103
- return self.tokenizer.decode(torch.Tensor([103028]),
104
- skip_special_tokens=True)
 
105
 
106
  def maybe_autocast(self, dtype=torch.float16):
107
  # if on cpu, don't use autocast
@@ -194,6 +196,9 @@ class InternLMXComposerForCausalLM(PreTrainedModel):
194
  new_kargs = copy.deepcopy(self.gen_config)
195
  new_kargs.update(kwargs)
196
  return new_kargs
 
 
 
197
 
198
  def generate(self, text, image=None, **kwargs):
199
  text_embeds = self.encode_text(text)
 
95
 
96
  @property
97
  def eoh(self):
98
+ #return self.tokenizer.decode(torch.Tensor([103027]),
99
+ # skip_special_tokens=True)
100
+ return '<TOKENS_UNUSED_0>'
101
 
102
  @property
103
  def eoa(self):
104
+ #return self.tokenizer.decode(torch.Tensor([103028]),
105
+ # skip_special_tokens=True)
106
+ return '<TOKENS_UNUSED_1>'
107
 
108
  def maybe_autocast(self, dtype=torch.float16):
109
  # if on cpu, don't use autocast
 
196
  new_kargs = copy.deepcopy(self.gen_config)
197
  new_kargs.update(kwargs)
198
  return new_kargs
199
+
200
+ def forward(self, **kwargs):
201
+ return self.internlm_model(**kwargs)
202
 
203
  def generate(self, text, image=None, **kwargs):
204
  text_embeds = self.encode_text(text)
modeling_vit.py CHANGED
@@ -368,13 +368,13 @@ class VisionTransformer(nn.Module):
368
  window_size=self.patch_embed.patch_shape
369
  if use_rel_pos_bias else None) for i in range(depth)
370
  ])
371
-
372
- # if self.pos_embed is not None:
373
- # trunc_normal_(self.pos_embed, std=.02)
374
- # trunc_normal_(self.cls_token, std=.02)
375
- # self.apply(self._init_weights)
376
- # self.fix_init_weight()
377
-
378
  def fix_init_weight(self):
379
  def rescale(param, layer_id):
380
  param.div_(math.sqrt(2.0 * layer_id))
@@ -518,12 +518,12 @@ def create_eva_vit_g(img_size=224,
518
  norm_layer=partial(nn.LayerNorm, eps=1e-6),
519
  use_checkpoint=use_checkpoint,
520
  )
521
- # url = "https://storage.googleapis.com/sfr-vision-language-research/LAVIS/models/BLIP2/eva_vit_g.pth"
522
- # cached_file = download_cached_file(url, check_hash=False, progress=True)
523
- # state_dict = torch.load(cached_file, map_location="cpu")
524
- # interpolate_pos_embed(model, state_dict)
525
- #
526
- # incompatible_keys = model.load_state_dict(state_dict, strict=False)
527
 
528
  if precision == "fp16":
529
  convert_weights_to_fp16(model)
 
368
  window_size=self.patch_embed.patch_shape
369
  if use_rel_pos_bias else None) for i in range(depth)
370
  ])
371
+ '''
372
+ if self.pos_embed is not None:
373
+ trunc_normal_(self.pos_embed, std=.02)
374
+ trunc_normal_(self.cls_token, std=.02)
375
+ self.apply(self._init_weights)
376
+ self.fix_init_weight()
377
+ '''
378
  def fix_init_weight(self):
379
  def rescale(param, layer_id):
380
  param.div_(math.sqrt(2.0 * layer_id))
 
518
  norm_layer=partial(nn.LayerNorm, eps=1e-6),
519
  use_checkpoint=use_checkpoint,
520
  )
521
+ url = "https://storage.googleapis.com/sfr-vision-language-research/LAVIS/models/BLIP2/eva_vit_g.pth"
522
+ cached_file = download_cached_file(url, check_hash=False, progress=True)
523
+ state_dict = torch.load(cached_file, map_location="cpu")
524
+ interpolate_pos_embed(model, state_dict)
525
+
526
+ incompatible_keys = model.load_state_dict(state_dict, strict=False)
527
 
528
  if precision == "fp16":
529
  convert_weights_to_fp16(model)
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21ff673031fd4187f19721a86af4caa6a4deb1f3c2db284f763de3e53bd8f741
3
+ size 1658715