generate code refactoring progress 1/3
This commit is contained in:
+41
-2
@@ -1,10 +1,11 @@
|
||||
use std::time::Instant;
|
||||
use std::{pin::pin, time::Instant};
|
||||
|
||||
use aha::{
|
||||
models::{GenerateModel, minicpm5::generate::MiniCPM5GenerateModel},
|
||||
params::chat::ChatCompletionParameters,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use rocket::futures::StreamExt;
|
||||
#[test]
|
||||
fn minicpm5_generate() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_minicpm5 minicpm5_generate -r -- --nocapture
|
||||
@@ -16,7 +17,7 @@ fn minicpm5_generate() -> Result<()> {
|
||||
{
|
||||
"temperature": 0.3,
|
||||
"top_p": 0.8,
|
||||
"model": "minicpm4",
|
||||
"model": "minicpm5",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
@@ -39,3 +40,41 @@ fn minicpm5_generate() -> Result<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn minicpm5_stream() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_minicpm5 minicpm5_stream -r -- --nocapture
|
||||
|
||||
let save_dir =
|
||||
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
|
||||
let model_path = format!("{}/OpenBMB/MiniCPM5-1B/", save_dir);
|
||||
|
||||
let message = r#"
|
||||
{
|
||||
"model": "minicpm5",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "什么是AI"
|
||||
}
|
||||
],
|
||||
"enable_thinking": true
|
||||
}
|
||||
"#;
|
||||
let mes: ChatCompletionParameters = serde_json::from_str(message)?;
|
||||
let i_start = Instant::now();
|
||||
let mut model = MiniCPM5GenerateModel::init(&model_path, None, None)?;
|
||||
let i_duration = i_start.elapsed();
|
||||
println!("Time elapsed in load model is: {:?}", i_duration);
|
||||
|
||||
let i_start = Instant::now();
|
||||
let mut stream = pin!(model.generate_stream(mes)?);
|
||||
while let Some(item) = stream.next().await {
|
||||
println!("generate: \n {:?}", item);
|
||||
}
|
||||
|
||||
let i_duration = i_start.elapsed();
|
||||
println!("Time elapsed in generate is: {:?}", i_duration);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ fn qwen3_0_6b_generate() -> Result<()> {
|
||||
|
||||
#[tokio::test]
|
||||
async fn qwen3_0_6b_stream() -> Result<()> {
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda qwen3_0_6b_stream -r -- --nocapture
|
||||
// test with cuda: RUST_BACKTRACE=1 cargo test -F cuda --test test_qwen3 qwen3_0_6b_stream -r -- --nocapture
|
||||
|
||||
let save_dir =
|
||||
aha::utils::get_default_save_dir().ok_or(anyhow::anyhow!("Failed to get save dir"))?;
|
||||
|
||||
Reference in New Issue
Block a user