Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
f18b9c72
"git@developer.sourcefind.cn:change/sglang.git" did not exist on "33b16ad178573e54eba44999c5af4740b57affd1"
Unverified
Commit
f18b9c72
authored
Nov 12, 2024
by
RangiLyu
Committed by
GitHub
Nov 11, 2024
Browse files
support internlm2-reward (#1994)
parent
3e335743
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
0 deletions
+65
-0
docs/references/supported_models.md
docs/references/supported_models.md
+2
-0
python/sglang/srt/configs/model_config.py
python/sglang/srt/configs/model_config.py
+1
-0
python/sglang/srt/models/internlm2_reward.py
python/sglang/srt/models/internlm2_reward.py
+62
-0
No files found.
docs/references/supported_models.md
View file @
f18b9c72
...
...
@@ -42,6 +42,8 @@
-
`python -m sglang.launch_server --model-path Skywork/Skywork-Reward-Llama-3.1-8B-v0.2 --is-embedding`
-
Gemma2ForSequenceClassification
-
`python -m sglang.launch_server --model-path Skywork/Skywork-Reward-Gemma-2-27B-v0.2 --is-embedding`
-
InternLM2ForRewardModel
-
`python -m sglang.launch_server --model-path internlm/internlm2-7b-reward --is-embedding --trust-remote-code`
## How to Support a New Model
...
...
python/sglang/srt/configs/model_config.py
View file @
f18b9c72
...
...
@@ -210,6 +210,7 @@ def is_generation_model(model_architectures: List[str], is_embedding: bool = Fal
or
"MistralModel"
in
model_architectures
or
"LlamaForSequenceClassification"
in
model_architectures
or
"LlamaForSequenceClassificationWithNormal_Weights"
in
model_architectures
or
"InternLM2ForRewardModel"
in
model_architectures
):
return
False
else
:
...
...
python/sglang/srt/models/internlm2_reward.py
0 → 100644
View file @
f18b9c72
"""
Copyright 2023-2024 SGLang Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
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.
"""
from
typing
import
Iterable
,
Optional
,
Tuple
import
torch
from
torch
import
nn
from
transformers
import
PretrainedConfig
from
sglang.srt.layers.pooler
import
EmbeddingPoolerOutput
,
Pooler
,
PoolingType
from
sglang.srt.layers.quantization.base_config
import
QuantizationConfig
from
sglang.srt.model_executor.forward_batch_info
import
ForwardBatch
from
sglang.srt.models.internlm2
import
InternLM2ForCausalLM
,
InternLM2Model
class
InternLM2ForRewardModel
(
nn
.
Module
):
def
__init__
(
self
,
config
:
PretrainedConfig
,
quant_config
:
Optional
[
QuantizationConfig
]
=
None
,
cache_config
=
None
,
)
->
None
:
super
().
__init__
()
self
.
config
=
config
self
.
quant_config
=
quant_config
self
.
vocab_size
=
config
.
vocab_size
self
.
model
=
InternLM2Model
(
config
,
quant_config
)
self
.
v_head
=
nn
.
Linear
(
config
.
hidden_size
,
1
,
bias
=
False
)
self
.
pooler
=
Pooler
(
pooling_type
=
PoolingType
.
LAST
,
normalize
=
False
)
@
torch
.
no_grad
()
def
forward
(
self
,
input_ids
:
torch
.
Tensor
,
positions
:
torch
.
Tensor
,
forward_batch
:
ForwardBatch
,
input_embeds
:
torch
.
Tensor
=
None
,
get_embedding
:
bool
=
True
,
)
->
EmbeddingPoolerOutput
:
assert
get_embedding
,
"InternLM2ForRewardModel is only used for embedding"
hidden_states
=
self
.
model
(
input_ids
,
positions
,
forward_batch
,
input_embeds
)
last_token_hidden
=
self
.
pooler
(
hidden_states
,
forward_batch
).
embeddings
scores
=
self
.
v_head
(
last_token_hidden
)
return
EmbeddingPoolerOutput
(
scores
)
def
load_weights
(
self
,
weights
:
Iterable
[
Tuple
[
str
,
torch
.
Tensor
]]):
return
InternLM2ForCausalLM
.
load_weights
(
self
,
weights
)
EntryClass
=
InternLM2ForRewardModel
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment