-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5daf093
commit aed2595
Showing
9 changed files
with
160 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,3 @@ quant: | |
save: | ||
save_trans: False | ||
save_path: ./save | ||
tokenizer_file_substring: ["token"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,3 @@ quant: | |
save: | ||
save_trans: False | ||
save_path: ./save | ||
tokenizer_file_substring: ["token"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,3 @@ quant: | |
save: | ||
save_trans: False | ||
save_path: ./save | ||
tokenizer_file_substring: ["token"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from loguru import logger | ||
from transformers import AutoConfig, AutoModelForCausalLM | ||
|
||
from llmc.utils.registry_factory import MODEL_REGISTRY | ||
|
||
from .internlm2 import InternLM2 | ||
|
||
|
||
@MODEL_REGISTRY | ||
class InternVL2(InternLM2): | ||
def __init__(self, model_path, torch_dtype): | ||
super().__init__(model_path, torch_dtype) | ||
|
||
def build_model(self): | ||
self.vlm_model_config = AutoConfig.from_pretrained( | ||
self.model_path, trust_remote_code=True | ||
) | ||
if hasattr(self.vlm_model_config, 'use_cache'): | ||
self.vlm_model_config.use_cache = False | ||
logger.info(f'self.vlm_model_config : {self.vlm_model_config}') | ||
self.vlm_model = AutoModelForCausalLM.from_pretrained( | ||
self.model_path, | ||
config=self.vlm_model_config, | ||
trust_remote_code=True, | ||
torch_dtype=self.torch_dtype, | ||
low_cpu_mem_usage=True, | ||
) | ||
self.model = self.vlm_model.language_model | ||
self.model_config = self.vlm_model_config.llm_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from llmc.utils.registry_factory import MODEL_REGISTRY | ||
|
||
from .base_model import BaseModel | ||
|
||
|
||
@MODEL_REGISTRY | ||
class Qwen(BaseModel): | ||
def __init__(self, model_path, torch_dtype): | ||
super().__init__(model_path, torch_dtype) | ||
|
||
def find_blocks(self): | ||
self.blocks = self.model.transformer.h | ||
|
||
def find_embed_layers(self): | ||
self.wte = self.model.transformer.wte | ||
self.rotary_emb = self.model.transformer.rotary_emb | ||
|
||
def find_block_name(self): | ||
self.block_name_prefix = 'transformer.h' | ||
|
||
def get_embed_layers(self): | ||
return [self.wte, self.rotary_emb] | ||
|
||
def get_head_layers(self): | ||
return [self.model.lm_head] | ||
|
||
def get_pre_head_layernorm_layers(self): | ||
return [self.model.transformer.ln_f] | ||
|
||
def get_layers_except_blocks(self): | ||
return [self.wte, | ||
self.rotary_emb, | ||
self.model.transformer.ln_f, | ||
self.model.lm_head] | ||
|
||
def has_bias(self): | ||
return False | ||
|
||
def get_layernorms_in_block(self, block): | ||
return { | ||
'ln_1': block.ln_1, | ||
'ln_2': block.ln_2, | ||
} | ||
|
||
def get_num_attention_heads(self): | ||
return self.model_config.num_attention_heads | ||
|
||
def get_subsets_in_block(self, block): | ||
return [ | ||
{ | ||
'layers': { | ||
'attn.c_attn': block.attn.c_attn | ||
}, | ||
'prev_op': [block.ln_1], | ||
'input': ['attn.c_attn'], | ||
'inspect': block.attn, | ||
'has_kwargs': True, | ||
}, | ||
{ | ||
'layers': {'attn.c_proj': block.attn.c_proj}, | ||
'prev_op': [block.attn.c_attn], | ||
'input': ['attn.c_proj'], | ||
'inspect': block.attn.c_proj, | ||
'has_kwargs': False, | ||
}, | ||
{ | ||
'layers': { | ||
'mlp.w1': block.mlp.w1, | ||
'mlp.w2': block.mlp.w2, | ||
}, | ||
'prev_op': [block.ln_2], | ||
'input': ['mlp.w1'], | ||
'inspect': block.mlp, | ||
'has_kwargs': False, | ||
'is_mlp': True, | ||
}, | ||
{ | ||
'layers': {'mlp.c_proj': block.mlp.c_proj}, | ||
'prev_op': [block.mlp.w1], | ||
'input': ['mlp.c_proj'], | ||
'inspect': block.mlp.c_proj, | ||
'has_kwargs': False, | ||
'is_mlp': True, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from loguru import logger | ||
from transformers import AutoConfig, AutoModelForCausalLM | ||
|
||
from llmc.utils.registry_factory import MODEL_REGISTRY | ||
|
||
from .qwen import Qwen | ||
|
||
|
||
@MODEL_REGISTRY | ||
class QwenVL(Qwen): | ||
def __init__(self, model_path, torch_dtype): | ||
super().__init__(model_path, torch_dtype) | ||
|
||
def build_model(self): | ||
self.vlm_model_config = AutoConfig.from_pretrained( | ||
self.model_path, trust_remote_code=True | ||
) | ||
if hasattr(self.vlm_model_config, 'use_cache'): | ||
self.vlm_model_config.use_cache = False | ||
logger.info(f'self.vlm_model_config : {self.vlm_model_config}') | ||
self.vlm_model = AutoModelForCausalLM.from_pretrained( | ||
self.model_path, | ||
config=self.vlm_model_config, | ||
trust_remote_code=True, | ||
torch_dtype=self.torch_dtype, | ||
low_cpu_mem_usage=True, | ||
) | ||
self.model = self.vlm_model | ||
self.model_config = self.vlm_model_config | ||
self.vision_model = self.vlm_model.transformer.visual |