MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / forward_batch

Method forward_batch

python/cpp/encoder.cc:14–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12 using ReplicaPoolHelper::ReplicaPoolHelper;
13
14 EncoderForwardOutput
15 forward_batch(const std::variant<BatchTokens, BatchIds, StorageView>& inputs,
16 const std::optional<StorageView>& lengths,
17 const std::optional<BatchIds>& token_type_ids) {
18 std::future<EncoderForwardOutput> future;
19 std::shared_lock lock(_mutex);
20 assert_model_is_ready();
21
22 switch (inputs.index()) {
23 case 0:
24 future = _pool->forward_batch_async(
25 std::get<BatchTokens>(inputs),
26 token_type_ids.value_or(std::vector<std::vector<size_t>>()));
27 break;
28 case 1:
29 future = _pool->forward_batch_async(
30 std::get<BatchIds>(inputs),
31 token_type_ids.value_or(std::vector<std::vector<size_t>>()));
32 break;
33 case 2:
34 if (!lengths)
35 throw std::invalid_argument("lengths vector is required when passing a dense input");
36 future = _pool->forward_batch_async(
37 std::get<StorageView>(inputs),
38 lengths.value(),
39 token_type_ids.value_or(std::vector<std::vector<size_t>>()));
40 break;
41 }
42
43 return future.get();
44 }
45 };
46
47

Callers 3

_check_generator_logitsFunction · 0.45

Calls 4

indexMethod · 0.80
forward_batch_asyncMethod · 0.45
valueMethod · 0.45
getMethod · 0.45

Tested by 3

_check_generator_logitsFunction · 0.36