| 8 | namespace python { |
| 9 | |
| 10 | void register_generation_result(py::module& m) { |
| 11 | py::class_<GenerationStepResult>(m, "GenerationStepResult", |
| 12 | "The result for a single generation step.") |
| 13 | |
| 14 | .def_readonly("step", &GenerationStepResult::step, |
| 15 | "The decoding step.") |
| 16 | .def_readonly("batch_id", &GenerationStepResult::batch_id, |
| 17 | "The batch index.") |
| 18 | .def_readonly("token_id", &GenerationStepResult::token_id, |
| 19 | "ID of the generated token.") |
| 20 | .def_readonly("hypothesis_id", &GenerationStepResult::hypothesis_id, |
| 21 | "Index of the hypothesis in the batch.") |
| 22 | .def_readonly("token", &GenerationStepResult::token, |
| 23 | "String value of the generated token.") |
| 24 | .def_readonly("log_prob", &GenerationStepResult::score, |
| 25 | "Log probability of the token (``None`` if :obj:`return_log_prob` was disabled).") |
| 26 | .def_readonly("logits", &GenerationStepResult::logits, |
| 27 | "Log probability on the vocab of all tokens.") |
| 28 | .def_readonly("is_last", &GenerationStepResult::is_last, |
| 29 | "Whether this step is the last decoding step for this batch.") |
| 30 | |
| 31 | .def("__repr__", [](const GenerationStepResult& result) { |
| 32 | return "GenerationStepResult(step=" + std::string(py::repr(py::cast(result.step))) |
| 33 | + ", batch_id=" + std::string(py::repr(py::cast(result.batch_id))) |
| 34 | + ", token_id=" + std::string(py::repr(py::cast(result.token_id))) |
| 35 | + ", hypothesis_id=" + std::string(py::repr(py::cast(result.hypothesis_id))) |
| 36 | + ", token=" + std::string(py::repr(py::cast(result.token))) |
| 37 | + ", log_prob=" + std::string(py::repr(py::cast(result.score))) |
| 38 | + ", logits=" + std::string(py::repr(py::cast(result.logits))) |
| 39 | + ", is_last=" + std::string(py::repr(py::cast(result.is_last))) |
| 40 | + ")"; |
| 41 | }) |
| 42 | ; |
| 43 | |
| 44 | py::class_<GenerationResult>(m, "GenerationResult", "A generation result.") |
| 45 | |
| 46 | .def_readonly("sequences", &GenerationResult::sequences, |
| 47 | "Generated sequences of tokens.") |
| 48 | .def_readonly("sequences_ids", &GenerationResult::sequences_ids, |
| 49 | "Generated sequences of token IDs.") |
| 50 | .def_readonly("scores", &GenerationResult::scores, |
| 51 | "Score of each sequence (empty if :obj:`return_scores` was disabled).") |
| 52 | .def_readonly("logits", &GenerationResult::logits, |
| 53 | "Logits of each sequence (empty if :obj:`return_logits_vocab` was disabled).") |
| 54 | |
| 55 | .def("__repr__", [](const GenerationResult& result) { |
| 56 | return "GenerationResult(sequences=" + std::string(py::repr(py::cast(result.sequences))) |
| 57 | + ", sequences_ids=" + std::string(py::repr(py::cast(result.sequences_ids))) |
| 58 | + ", scores=" + std::string(py::repr(py::cast(result.scores))) |
| 59 | + ", logits=" + std::string(py::repr(py::cast(result.logits))) |
| 60 | + ")"; |
| 61 | }) |
| 62 | ; |
| 63 | |
| 64 | declare_async_wrapper<GenerationResult>(m, "AsyncGenerationResult"); |
| 65 | } |
| 66 | |
| 67 | } |
no test coverage detected