-
Notifications
You must be signed in to change notification settings - Fork 3k
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
move modeling.py and modeling_nv.py to transformers #9676
base: develop
Are you sure you want to change the base?
Conversation
Thanks for your contribution! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9676 +/- ##
===========================================
+ Coverage 52.00% 52.62% +0.62%
===========================================
Files 721 722 +1
Lines 116703 112813 -3890
===========================================
- Hits 60690 59373 -1317
+ Misses 56013 53440 -2573 ☔ View full report in Codecov by Sentry. |
Lint 问题需要安装pre-commit 后格式化代码,参考步骤如下: # 安装
pip install pre-commit
# 在项目文件夹下注册pre-commit,每次commit提交时都会格式化代码
pre-commit install
# 单独处理之前的代码文件
pre-commit run --file XXXX.py |
@@ -0,0 +1,13 @@ | |||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
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.
这里的copyright是否正确?
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.
已修改
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
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.
此处增加from .modeling import *
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.
已添加
PretrainedModel, | ||
) | ||
from paddlenlp.transformers.model_outputs import ModelOutput | ||
from paddlenlp.utils.log import logger |
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.
这里的调用需要修改为相对引用方式
例如:
from paddlenlp.transformers.model_outputs import ModelOutput
修改为
from ..transformers.model_outputs import ModelOutput
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.
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.
此处应该为 from ..model_outputs import ModelOutput
,抱歉之前写错了
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.
已修改
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
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.
同上,此处增加from .modeling import *
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.
已添加
@@ -0,0 +1,517 @@ | |||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. |
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.
此文件需要修改名称为modeling.py
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.
已修改
from mteb import MTEB | ||
|
||
from paddlenlp.peft import LoRAConfig, LoRAModel | ||
from paddlenlp.transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer | ||
from paddlenlp.transformers.llm_embed.modeling import BiEncoderModel | ||
from paddlenlp.transformers.nv_embed.modeling_nv import NVEncodeModel |
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.
此处可以简化导入
from paddlenlp.transformers import BiEncoderModel, NVEncodeModel
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.
已修改
|
||
from paddlenlp.peft import LoRAConfig, LoRAModel | ||
from paddlenlp.trainer import PdArgumentParser, Trainer, get_last_checkpoint, set_seed | ||
from paddlenlp.transformers import AutoTokenizer | ||
from paddlenlp.transformers.llm_embed.modeling import BiEncoderModel | ||
from paddlenlp.transformers.nv_embed.modeling_nv import NVEncodeModel |
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.
同上
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.
已修改
已按照您所说步骤在commit之前进行了pre-commit |
dtype=str(self.latents.weight.dtype).split(".")[-1], | ||
) | ||
self_latents_weight_T = self.latents(one).T | ||
latents = repeat(self_latents_weight_T, "d h -> b d h", b=last_hidden_states.shape[0]) |
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.
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.
已修改为
latents = paddle.tile(self_latents_weight_T, repeat_times=last_hidden_states.shape[0]).reshape( self_latents_weight_T.shape[0], last_hidden_states.shape[0], self_latents_weight_T.shape[1] ) latents = latents.transpose([1, 0, 2])
k = kv[:, :, : self.config.max_position_embeddings] | ||
v = kv[:, :, self.config.max_position_embeddings :] | ||
|
||
q, k, v = map(lambda t: rearrange(t, "b n (h d) -> b n h d", h=self.config.num_key_value_heads), (q, k, v)) |
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.
rearrange辛苦换为paddle算子
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.
已修改
# v.stop_gradient = False | ||
# out = paddle.nn.functional.scaled_dot_product_attention(q, k, v) # if use this, must set k and v stop_gradient to False | ||
out = scaled_dot_product_attention(q, k, v) # if use this, no need to manually set k and v | ||
out = rearrange(out, "b n h d -> b n (h d)", h=self.config.num_key_value_heads) |
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.
同上修改
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.
已修改
move modeling.py and modeling_nv.py to transformers