summaryrefslogtreecommitdiff
path: root/candle-examples/examples/t5/main.rs
diff options
context:
space:
mode:
authorLaurent Mazare <laurent.mazare@gmail.com>2023-09-17 11:25:54 +0200
committerGitHub <noreply@github.com>2023-09-17 10:25:54 +0100
commit7f65af1f0dc518ef17623d718f3901f58c3aab06 (patch)
tree0dad24520bc3ae757ace350fc876fba683d5f908 /candle-examples/examples/t5/main.rs
parenteeb54716dd2635aa3dd9943fd3009eae863df71b (diff)
downloadcandle-7f65af1f0dc518ef17623d718f3901f58c3aab06.tar.gz
candle-7f65af1f0dc518ef17623d718f3901f58c3aab06.tar.bz2
candle-7f65af1f0dc518ef17623d718f3901f58c3aab06.zip
Avoid re-encoding the input in the T5 example. (#875)
Diffstat (limited to 'candle-examples/examples/t5/main.rs')
-rw-r--r--candle-examples/examples/t5/main.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/candle-examples/examples/t5/main.rs b/candle-examples/examples/t5/main.rs
index 72be23bc..36cbee7c 100644
--- a/candle-examples/examples/t5/main.rs
+++ b/candle-examples/examples/t5/main.rs
@@ -171,6 +171,7 @@ fn main() -> Result<()> {
Some(args.temperature)
};
let mut logits_processor = LogitsProcessor::new(299792458, temperature, args.top_p);
+ let encoder_output = model.encode(&input_token_ids)?;
let start = std::time::Instant::now();
for index in 0.. {
@@ -184,7 +185,7 @@ fn main() -> Result<()> {
Tensor::new(&[last_token], device)?.unsqueeze(0)?
};
let logits = model
- .forward(&input_token_ids, &decoder_token_ids)?
+ .decode(&decoder_token_ids, &encoder_output)?
.squeeze(0)?;
let logits = if args.repeat_penalty == 1. {
logits