#![allow(clippy::disallowed_methods)]
#![allow(unused_imports)]
use aprender::autograd::Tensor;
use aprender::demo::Qwen2Config;
use aprender::models::Qwen2Model;
use aprender::nn::Module;
use aprender::text::bpe::Qwen2BpeTokenizer;
#[test]
fn z1_tinyllama_imports_to_apr() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("TinyLlama") && spec.contains("import"),
"Z1: Spec must document TinyLlama import capability"
);
assert!(
spec.contains("RMSNorm") && spec.contains("validation"),
"Z1: Spec must document RMSNorm validation fix"
);
let import_cmd = "crates/apr-cli/src/commands/import.rs";
if let Ok(content) = std::fs::read_to_string(import_cmd) {
assert!(
content.contains("safetensors") || content.contains("import"),
"Z1: Import command must handle safetensors"
);
}
}
#[test]
fn z2_qwencoder_imports_to_apr() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("Qwen2.5-Coder") || spec.contains("QwenCoder"),
"Z2: Spec must document Qwen2.5-Coder import"
);
assert!(
spec.contains("--arch qwen2") || spec.contains("Architecture::Qwen2"),
"Z2: Spec must document --arch qwen2 support"
);
let format_path = "src/format/mod.rs";
if let Ok(content) = std::fs::read_to_string(format_path) {
assert!(
content.contains("Qwen2") || content.contains("Architecture"),
"Z2: Format module should support Qwen2 architecture"
);
}
}
#[test]
fn z3_tinyllama_serving_http() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("apr serve") || spec.contains("Serving"),
"Z3: Spec must document apr serve command"
);
assert!(
spec.contains("v1_compat") || spec.contains("APR2") || spec.contains("APRN"),
"Z3: Spec must document APR v1/v2 magic compatibility"
);
let serve_cmd = "crates/apr-cli/src/commands/serve.rs";
if std::fs::metadata(serve_cmd).is_ok() {
let content = std::fs::read_to_string(serve_cmd).expect("serve.rs exists");
assert!(
content.contains("async") || content.contains("tokio") || content.contains("axum"),
"Z3: Serve command must use async runtime"
);
}
}
#[test]
fn z4_qwencoder_serving_http() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("code completion")
|| spec.contains("Code generation")
|| spec.contains("IDE"),
"Z4: Spec must document code completion use case"
);
assert!(
spec.contains("Qwen") && (spec.contains("serve") || spec.contains("Serving")),
"Z4: Spec must document Qwen serving capability"
);
}
#[test]
fn z5_tinyllama_cpu_performance() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("tok/s") && spec.contains("TinyLlama"),
"Z5: Spec must document TinyLlama performance targets"
);
assert!(
spec.contains("--fast") || spec.contains("realizar"),
"Z5: Spec must document --fast flag for optimized inference"
);
assert!(
spec.contains("206") || spec.contains("185") || spec.contains("352"),
"Z5: Spec must document achieved performance > 60 tok/s"
);
}
#[test]
fn z6_qwencoder_cpu_performance() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("tok/s") && (spec.contains("Qwen") || spec.contains("QwenCoder")),
"Z6: Spec must document Qwen performance targets"
);
assert!(
spec.contains("realizar") && spec.contains("inference"),
"Z6: Spec must document realizar-based inference"
);
}
#[test]
fn z7_server_latency_ttft() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("TTFT") || spec.contains("latency") || spec.contains("50ms"),
"Z7: Spec must document TTFT latency requirement"
);
assert!(
spec.contains("Server") || spec.contains("serve"),
"Z7: Spec must document server latency expectations"
);
}
#[test]
fn z8_qwencoder_accuracy() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("Code") && (spec.contains("generation") || spec.contains("completion")),
"Z8: Spec must document code generation capability"
);
assert!(
spec.contains("syntax") || spec.contains("quality") || spec.contains("accuracy"),
"Z8: Spec must document quality expectations"
);
}
#[test]
fn z9_high_load_stability() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("concurrent") || spec.contains("stability") || spec.contains("load"),
"Z9: Spec must document concurrency/stability requirements"
);
let serve_cmd = "crates/apr-cli/src/commands/serve.rs";
if let Ok(content) = std::fs::read_to_string(serve_cmd) {
assert!(
content.contains("async") || content.contains("spawn") || content.contains("tokio"),
"Z9: Serve command must support concurrent connections"
);
}
}
#[test]
fn z10_zero_overhead_serving() {
let spec_path = "docs/specifications/archive/apr-whisper-and-cookbook-support-eoy-2025.md";
let spec = std::fs::read_to_string(spec_path).expect("Specification should exist");
assert!(
spec.contains("overhead") || spec.contains("bench") || spec.contains("5%"),
"Z10: Spec must document serving overhead expectations"
);
assert!(
spec.contains("apr bench") || spec.contains("benchmark"),
"Z10: Spec must document benchmark comparison"
);
}
#[test]
fn z_import_qwen2_0_5b_instruct_infra() {
use aprender::format::{Architecture, ImportOptions, Source, ValidationConfig};
let source = Source::parse("hf://Qwen/Qwen2-0.5B-Instruct").unwrap();
match source {
Source::HuggingFace { org, repo, .. } => {
assert_eq!(org, "Qwen", "HF org should be Qwen");
assert_eq!(repo, "Qwen2-0.5B-Instruct", "HF repo should match");
}
_ => panic!("Should parse as HuggingFace source"),
}
let arch = Architecture::Qwen2;
let mapped = arch.map_name("model.embed_tokens.weight");
assert_eq!(
mapped, "model.embed_tokens.weight",
"Qwen2 preserves model. prefix"
);
let options = ImportOptions {
architecture: Architecture::Qwen2,
validation: ValidationConfig::Strict,
quantize: None,
compress: None,
strict: false,
cache: true,
tokenizer_path: None,
allow_no_config: false,
};
assert_eq!(options.architecture, Architecture::Qwen2);
let config = Qwen2Config::qwen2_0_5b_instruct();
assert_eq!(config.hidden_size, 896);
assert_eq!(config.vocab_size, 151936);
}
#[test]
fn z_import_qwen25_coder_0_5b_infra() {
use aprender::format::{Architecture, ImportOptions, Source, ValidationConfig};
let source = Source::parse("hf://Qwen/Qwen2.5-Coder-0.5B-Instruct").unwrap();
match source {
Source::HuggingFace { org, repo, .. } => {
assert_eq!(org, "Qwen", "HF org should be Qwen");
assert_eq!(repo, "Qwen2.5-Coder-0.5B-Instruct", "HF repo should match");
}
_ => panic!("Should parse as HuggingFace source"),
}
let arch = Architecture::Qwen2;
let mapped = arch.map_name("model.layers.0.mlp.gate_proj.weight");
assert!(
mapped.contains("mlp.gate_proj.weight"),
"Qwen2 maps MLP names"
);
let options = ImportOptions {
architecture: Architecture::Qwen2,
validation: ValidationConfig::Basic,
quantize: Some(aprender::format::converter::QuantizationType::Int4),
compress: None,
strict: false,
cache: false,
tokenizer_path: None,
allow_no_config: false,
};
assert!(options.quantize.is_some(), "INT4 quantization supported");
let config = Qwen2Config::qwen25_coder_0_5b_instruct();
assert_eq!(config.hidden_size, 896, "Same hidden_size as Qwen2-0.5B");
assert_eq!(config.num_layers, 24, "Same num_layers as Qwen2-0.5B");
}
#[test]
fn z_import_qwen2_tensor_mappings() {
use aprender::format::Architecture;
let arch = Architecture::Qwen2;
let patterns = [
("model.embed_tokens.weight", "model.embed_tokens.weight"),
(
"model.layers.0.self_attn.q_proj.weight",
"model.layers.0.self_attn.q_proj.weight",
),
(
"model.layers.0.self_attn.k_proj.weight",
"model.layers.0.self_attn.k_proj.weight",
),
(
"model.layers.0.self_attn.v_proj.weight",
"model.layers.0.self_attn.v_proj.weight",
),
(
"model.layers.0.self_attn.o_proj.weight",
"model.layers.0.self_attn.o_proj.weight",
),
(
"model.layers.0.mlp.gate_proj.weight",
"model.layers.0.mlp.gate_proj.weight",
),
(
"model.layers.0.mlp.up_proj.weight",
"model.layers.0.mlp.up_proj.weight",
),
(
"model.layers.0.mlp.down_proj.weight",
"model.layers.0.mlp.down_proj.weight",
),
(
"model.layers.0.input_layernorm.weight",
"model.layers.0.input_layernorm.weight",
),
(
"model.layers.0.post_attention_layernorm.weight",
"model.layers.0.post_attention_layernorm.weight",
),
("model.norm.weight", "model.norm.weight"),
("lm_head.weight", "lm_head.weight"),
];
for (input, expected) in patterns {
let mapped = arch.map_name(input);
assert_eq!(mapped, expected, "Mapping for {input} should match");
}
}
#[test]
#[ignore = "Requires TinyLlama model file - run manually with model"]
fn z1_e2e_tinyllama_import() {
println!("Z1-E2E: Would test TinyLlama import with real model file");
}
#[test]
#[ignore = "Requires QwenCoder model and server - run manually"]
fn z4_e2e_qwencoder_serving() {
println!("Z4-E2E: Would test QwenCoder serving with real model");
}
#[test]
#[ignore = "Requires running server - run manually"]
fn z7_e2e_ttft_latency() {
println!("Z7-E2E: Would measure TTFT latency");
}
#[test]
#[ignore = "Requires running server - stress test manually"]
fn z9_e2e_high_load_stability() {
println!("Z9-E2E: Would test 50 concurrent connections");
}
#[test]
#[ignore = "Requires model file - run manually"]
fn z10_e2e_overhead_comparison() {
println!("Z10-E2E: Would compare bench vs serve performance");
}