Skip to content

Commit a727430

Browse files
committed
Revert "feat: add ERNIE 4.5 VL support"
This reverts commit 985e10a.
1 parent 985e10a commit a727430

23 files changed

Lines changed: 53 additions & 2209 deletions

‎csrc/engine/compiler/paged_compiler.cpp‎

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44

55
namespace infinilm::engine {
66

7-
namespace {
8-
bool same_shape_and_dtype(const infinicore::Tensor &lhs, const infinicore::Tensor &rhs) {
9-
return lhs->shape() == rhs->shape() && lhs->dtype() == rhs->dtype();
10-
}
11-
12-
bool is_mrope_decode_position_ids(const infinicore::Tensor &position_ids, size_t batch_size) {
13-
const auto shape = position_ids->shape();
14-
return shape.size() == 2 && shape[0] == batch_size && shape[1] == 3;
15-
}
16-
} // namespace
17-
187
PagedCompiler::PagedCompiler(const std::shared_ptr<InfinilmModel> &model, RankBarrier *barrier)
198
: GraphCompiler(model, barrier) {
209
for (size_t b = 1; b < 64; ++b) {
@@ -36,19 +25,14 @@ void PagedCompiler::compile() {
3625
size_t nblocks = dynamic_cast<const cache::PagedKVCacheConfig *>(model_->get_cache_config())->num_blocks();
3726
size_t max_batch_size = *std::max_element(decode_batch_sizes_.begin(), decode_batch_sizes_.end());
3827
compiled_map_decode_.clear();
39-
compiled_map_decode_mrope_.clear();
4028
block_tables_holder_ = infinicore::Tensor::empty(
4129
{nblocks * max_batch_size}, infinicore::DataType::I32, infinicore::context::getDevice());
4230
set_zeros(block_tables_holder_);
4331

44-
auto make_decode_input = [&](size_t b, bool mrope_position_ids) {
32+
auto make_decode_input = [&](size_t b) {
4533
InfinilmModel::Input input;
4634
input.input_ids = infinicore::Tensor::empty({1, b}, infinicore::DataType::I64, infinicore::context::getDevice());
47-
if (mrope_position_ids) {
48-
input.position_ids = infinicore::Tensor::empty({b, 3}, infinicore::DataType::I64, infinicore::context::getDevice());
49-
} else {
50-
input.position_ids = infinicore::Tensor::empty({b}, infinicore::DataType::I64, infinicore::context::getDevice());
51-
}
35+
input.position_ids = infinicore::Tensor::empty({b}, infinicore::DataType::I64, infinicore::context::getDevice());
5236
input.total_sequence_lengths = infinicore::Tensor::empty({b}, infinicore::DataType::I32, infinicore::context::getDevice());
5337
set_zeros(input.input_ids.value());
5438
set_zeros(input.position_ids.value());
@@ -82,7 +66,7 @@ void PagedCompiler::compile() {
8266

8367
{
8468
const size_t warmup_batch_size = std::min(max_batch_size, static_cast<size_t>(64));
85-
auto input = make_decode_input(warmup_batch_size, false);
69+
auto input = make_decode_input(warmup_batch_size);
8670
model_->forward(input);
8771
infinicore::context::syncStream();
8872
// Warmup runs the eager Marlin path and may leave per-layer lock
@@ -92,10 +76,8 @@ void PagedCompiler::compile() {
9276
infinicore::context::syncStream();
9377
}
9478

95-
auto capture_decode_graph = [&](size_t b,
96-
bool mrope_position_ids,
97-
std::unordered_map<size_t, CompiledResult> &compiled_map) {
98-
auto input = make_decode_input(b, mrope_position_ids);
79+
for (size_t b : decode_batch_sizes_) {
80+
auto input = make_decode_input(b);
9981

10082
barrier_->wait();
10183
(void)model_->forward(input);
@@ -114,15 +96,7 @@ void PagedCompiler::compile() {
11496
auto shared_output = std::shared_ptr<InfinilmModel::Output>(
11597
new InfinilmModel::Output{infinicore::graph::GraphTensor(output.logits)});
11698

117-
compiled_map[b] = CompiledResult{std::move(input), std::make_tuple(graph, shared_output)};
118-
};
119-
120-
const bool compile_mrope_decode = model_->supports_mrope_position_ids();
121-
for (size_t b : decode_batch_sizes_) {
122-
capture_decode_graph(b, false, compiled_map_decode_);
123-
if (compile_mrope_decode) {
124-
capture_decode_graph(b, true, compiled_map_decode_mrope_);
125-
}
99+
compiled_map_decode_[b] = CompiledResult{std::move(input), std::make_tuple(graph, shared_output)};
126100
}
127101
}
128102
}
@@ -136,23 +110,12 @@ PagedCompiler::Compiled PagedCompiler::get_compiled(const InfinilmModel::Input &
136110
if (batch_size != input.input_ids.value()->size(1)) {
137111
return {nullptr, nullptr};
138112
} else {
139-
const bool mrope_position_ids = is_mrope_decode_position_ids(input.position_ids.value(), batch_size);
140-
auto &compiled_map = mrope_position_ids ? compiled_map_decode_mrope_ : compiled_map_decode_;
141-
auto result = compiled_map.find(batch_size);
142-
if (result == compiled_map.end()) {
113+
auto result = compiled_map_decode_.find(batch_size);
114+
if (result == compiled_map_decode_.end()) {
143115
return {nullptr, nullptr};
144116
}
145117
auto &graph_input = result->second.input;
146118

147-
if (!same_shape_and_dtype(graph_input.input_ids.value(), input.input_ids.value()) ||
148-
!same_shape_and_dtype(graph_input.position_ids.value(), input.position_ids.value()) ||
149-
!same_shape_and_dtype(graph_input.total_sequence_lengths.value(), input.total_sequence_lengths.value()) ||
150-
!same_shape_and_dtype(graph_input.input_offsets.value(), input.input_offsets.value()) ||
151-
!same_shape_and_dtype(graph_input.cu_seqlens.value(), input.cu_seqlens.value()) ||
152-
!same_shape_and_dtype(graph_input.slot_mapping.value(), input.slot_mapping.value())) {
153-
return {nullptr, nullptr};
154-
}
155-
156119
graph_input.input_ids.value()->copy_from(input.input_ids.value());
157120
graph_input.position_ids.value()->copy_from(input.position_ids.value());
158121
graph_input.total_sequence_lengths.value()->copy_from(input.total_sequence_lengths.value());
@@ -169,9 +132,6 @@ PagedCompiler::Compiled PagedCompiler::get_compiled(const InfinilmModel::Input &
169132
// runtime logical region. Avoid clearing the full preallocated
170133
// holder on every decode token.
171134
auto &graph_block_tables = graph_input.block_tables.value();
172-
if (graph_block_tables->dtype() != input.block_tables.value()->dtype()) {
173-
return {nullptr, nullptr};
174-
}
175135
set_minus_one_device_async(graph_block_tables);
176136
graph_block_tables->narrow({{1, 0, block_per_req}})->copy_from(input.block_tables.value());
177137
graph_input.slot_mapping.value()->copy_from(input.slot_mapping.value());

‎csrc/engine/compiler/paged_compiler.hpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,5 @@ class PagedCompiler : public GraphCompiler {
2727
size_t, // num_requests
2828
CompiledResult>
2929
compiled_map_decode_;
30-
31-
std::unordered_map<
32-
size_t, // num_requests
33-
CompiledResult>
34-
compiled_map_decode_mrope_;
3530
};
3631
} // namespace infinilm::engine

‎csrc/layers/linear/fused_linear.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ GateUpParallelLinear::GateUpParallelLinear(size_t hidden_size, size_t intermedia
151151

152152
std::tuple<infinicore::Tensor, infinicore::Tensor> GateUpParallelLinear::forward_split(infinicore::Tensor &input) {
153153
auto output = this->forward(input);
154-
const size_t split_dim = output->ndim() - 1;
155-
auto cols = output->size(split_dim);
156-
auto gate_output = output->narrow({{split_dim, 0, cols / 2}});
157-
auto up_output = output->narrow({{split_dim, cols / 2, cols / 2}});
154+
auto cols = output->shape()[2];
155+
auto gate_output = output->narrow({{2, 0, cols / 2}});
156+
auto up_output = output->narrow({{2, cols / 2, cols / 2}});
158157
return std::make_tuple(gate_output, up_output);
159158
}
160159

‎csrc/layers/moe/router/topk_router.cpp‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "topk_router.hpp"
22

3-
#include "../../../utils.hpp"
43
#include "infinicore/ops.hpp"
54

65
#include <stdexcept>
@@ -13,9 +12,6 @@ TopKRouterBackend parse_router_backend(const std::string &backend) {
1312
if (backend == "softmax") {
1413
return TopKRouterBackend::Softmax;
1514
}
16-
if (backend == "topksoftmax" || backend == "legacy_softmax") {
17-
return TopKRouterBackend::LegacySoftmax;
18-
}
1915
if (backend == "sigmoid") {
2016
return TopKRouterBackend::Sigmoid;
2117
}
@@ -57,13 +53,9 @@ TopKRouter::TopKRouter(std::shared_ptr<infinilm::config::ModelConfig> model_conf
5753
use_correction_bias_ = model_config->get_or<bool>({"e_score_correction_bias", "moe_router_use_correction_bias"}, false) || router_backend_ == TopKRouterBackend::FusedGate;
5854
ASSERT((num_experts_ > 0) && (num_experts_per_tok_ > 0) && (num_experts_per_tok_ <= num_experts_));
5955

60-
const auto router_dtype_name = model_config->get_or<std::string>("moe_router_dtype", "");
61-
const auto router_dtype = router_dtype_name.empty()
62-
? model_config->get_dtype()
63-
: parse_dtype(router_dtype_name);
6456
INFINICORE_NN_PARAMETER_INIT(
6557
weight,
66-
({num_experts_, model_config->get<size_t>("hidden_size")}, router_dtype, device));
58+
({num_experts_, model_config->get<size_t>("hidden_size")}, model_config->get_dtype(), device));
6759

6860
if (use_correction_bias_) {
6961
INFINICORE_NN_PARAMETER_INIT(e_score_correction_bias, ({num_experts_}, infinicore::DataType::F32, device));
@@ -87,17 +79,9 @@ TopKRouter::TopKRouter(std::shared_ptr<infinilm::config::ModelConfig> model_conf
8779

8880
std::tuple<infinicore::Tensor, infinicore::Tensor> TopKRouter::forward(const infinicore::Tensor &hidden_states) const {
8981
ASSERT(hidden_states->ndim() == 2);
82+
9083
size_t ntoken = hidden_states->shape()[0];
91-
auto router_input = hidden_states->is_contiguous() ? hidden_states : hidden_states->contiguous();
92-
auto router_weight = static_cast<infinicore::Tensor>(weight_);
93-
router_weight = router_weight->is_contiguous() ? router_weight : router_weight->contiguous();
94-
auto logits_shape = router_input->shape();
95-
logits_shape[logits_shape.size() - 1] = num_experts_;
96-
auto router_logits = infinicore::Tensor::empty(
97-
logits_shape,
98-
router_weight->dtype(),
99-
router_input->device());
100-
infinicore::op::linear_(router_logits, router_input, router_weight, std::nullopt, 1.0f);
84+
auto router_logits = infinicore::op::linear(hidden_states, weight_, std::nullopt, 1.0f);
10185

10286
auto router_scores = infinicore::Tensor::empty({ntoken, num_experts_per_tok_}, infinicore::DataType::F32, hidden_states->device());
10387
auto router_indices = infinicore::Tensor::empty({ntoken, num_experts_per_tok_}, infinicore::DataType::I32, hidden_states->device());
@@ -114,14 +98,6 @@ std::tuple<infinicore::Tensor, infinicore::Tensor> TopKRouter::forward(const inf
11498
norm_topk_prob_,
11599
moe_softcapping_);
116100
break;
117-
case TopKRouterBackend::LegacySoftmax:
118-
infinicore::op::topksoftmax(
119-
router_scores,
120-
router_indices,
121-
router_logits,
122-
num_experts_per_tok_,
123-
norm_topk_prob_);
124-
break;
125101
case TopKRouterBackend::Sigmoid:
126102
infinicore::op::moe_topk_sigmoid_(
127103
router_scores,

‎csrc/layers/moe/router/topk_router.hpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace infinilm::layers::moe {
1111

1212
enum class TopKRouterBackend {
1313
Softmax,
14-
LegacySoftmax,
1514
Sigmoid,
1615
FusedGate,
1716
};

‎csrc/models/ernie4_5_moe_vl/ernie4_5_attention.cpp‎

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)