-
Notifications
You must be signed in to change notification settings - Fork 648
Support fp32 head for qwen and internlm models #4160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,12 +7,13 @@ | |||||
| from transformers.configuration_utils import PretrainedConfig | ||||||
|
|
||||||
| from lmdeploy.pytorch.model_inputs import StepContext, StepContextManager | ||||||
| from lmdeploy.pytorch.nn import ApplyRotaryEmb, Attention, RMSNorm, SiluAndMul, build_rotary_embedding_from_config | ||||||
| from lmdeploy.pytorch.nn.linear import (build_down_linear, build_gateup_linear, build_o_proj, build_qkv_proj, | ||||||
| build_rowwise_linear) | ||||||
| from lmdeploy.pytorch.nn import (ApplyRotaryEmb, Attention, ParallelEmbedding, RMSNorm, SiluAndMul, | ||||||
| build_rotary_embedding_from_config) | ||||||
| from lmdeploy.pytorch.nn.linear import build_down_linear, build_gateup_linear, build_o_proj, build_qkv_proj | ||||||
| from lmdeploy.pytorch.weight_loader.model_weight_loader import load_weight | ||||||
|
|
||||||
| from .utils.cudagraph import CudaGraphMixin | ||||||
| from .utils.model import DeployModelMixinV1 | ||||||
|
|
||||||
|
|
||||||
| class InternLM2Attention(nn.Module): | ||||||
|
|
@@ -208,12 +209,13 @@ def __init__(self, config: PretrainedConfig, dtype: torch.dtype = None, device: | |||||
| self.padding_idx = config.pad_token_id | ||||||
| self.vocab_size = config.vocab_size | ||||||
|
|
||||||
| self.tok_embeddings = nn.Embedding(config.vocab_size, | ||||||
| config.hidden_size, | ||||||
| self.padding_idx, | ||||||
| dtype=dtype, | ||||||
| device=device) | ||||||
|
|
||||||
| self.tok_embeddings = ParallelEmbedding( | ||||||
| config.vocab_size, | ||||||
| config.hidden_size, | ||||||
| self.padding_idx, | ||||||
| dtype=dtype, | ||||||
| device=device, | ||||||
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head') else None) | ||||||
|
||||||
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head') else None) | |
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head', False) else None) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,12 +7,13 @@ | |||||
| from transformers.configuration_utils import PretrainedConfig | ||||||
|
|
||||||
| from lmdeploy.pytorch.model_inputs import StepContext, StepContextManager | ||||||
| from lmdeploy.pytorch.nn import ApplyRotaryEmb, Attention, RMSNorm, SiluAndMul, build_rotary_embedding_from_config | ||||||
| from lmdeploy.pytorch.nn.linear import (build_down_linear, build_gateup_linear, build_o_proj, build_qkv_proj, | ||||||
| build_rowwise_linear) | ||||||
| from lmdeploy.pytorch.nn import (ApplyRotaryEmb, Attention, ParallelEmbedding, RMSNorm, SiluAndMul, | ||||||
| build_rotary_embedding_from_config) | ||||||
| from lmdeploy.pytorch.nn.linear import build_down_linear, build_gateup_linear, build_o_proj, build_qkv_proj | ||||||
| from lmdeploy.pytorch.weight_loader.model_weight_loader import load_weight | ||||||
|
|
||||||
| from .utils.cudagraph import CudaGraphMixin | ||||||
| from .utils.model import DeployModelMixinV1 | ||||||
|
|
||||||
|
|
||||||
| class InternLM3Attention(nn.Module): | ||||||
|
|
@@ -210,11 +211,14 @@ def __init__(self, config: PretrainedConfig, dtype: torch.dtype = None, device: | |||||
| self.padding_idx = config.pad_token_id | ||||||
| self.vocab_size = config.vocab_size | ||||||
|
|
||||||
| self.embed_tokens = nn.Embedding(config.vocab_size, | ||||||
| config.hidden_size, | ||||||
| self.padding_idx, | ||||||
| dtype=dtype, | ||||||
| device=device) | ||||||
| self.embed_tokens = ParallelEmbedding( | ||||||
| config.vocab_size, | ||||||
| config.hidden_size, | ||||||
| self.padding_idx, | ||||||
| dtype=dtype, | ||||||
| device=device, | ||||||
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head') else None, | ||||||
|
||||||
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head') else None, | |
| force_dtype=torch.float32 if getattr(config, 'enforce_fp32_head', False) else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
getattr(config, 'enforce_fp32_head')without a default value will raise an AttributeError if the attribute doesn't exist. This can happen if the config was created before theenforce_fp32_headattribute was set, or if the configuration flow is bypassed.Use
getattr(config, 'enforce_fp32_head', False)instead to provide a safe default value.