1+ use std:: fs;
2+ use tempfile:: TempDir ;
3+ use shimmy:: engine:: llama:: LlamaEngine ;
4+ use shimmy:: engine:: { GenOptions , ModelSpec } ;
5+
6+ #[ cfg( test) ]
7+ mod tests {
8+ use super :: * ;
9+
10+ #[ test]
11+ fn test_calculate_adaptive_batch_size ( ) {
12+ // Test with small context (should use base size)
13+ let small_ctx = LlamaEngine :: calculate_adaptive_batch_size ( 1024 ) ;
14+ assert_eq ! ( small_ctx, 2048 , "Small contexts should use base batch size" ) ;
15+
16+ // Test with medium context (should use base size)
17+ let medium_ctx = LlamaEngine :: calculate_adaptive_batch_size ( 4096 ) ;
18+ assert_eq ! ( medium_ctx, 4096 , "Medium contexts should scale up" ) ;
19+
20+ // Test with large context (should be capped)
21+ let large_ctx = LlamaEngine :: calculate_adaptive_batch_size ( 16384 ) ;
22+ assert_eq ! ( large_ctx, 8192 , "Large contexts should be capped at 8192" ) ;
23+
24+ // Test edge case at cap
25+ let at_cap = LlamaEngine :: calculate_adaptive_batch_size ( 8192 ) ;
26+ assert_eq ! ( at_cap, 8192 , "Context at cap should use cap value" ) ;
27+ }
28+
29+ #[ test]
30+ fn test_large_prompt_batch_size_calculation ( ) {
31+ // This test ensures that contexts large enough to handle the reported issue
32+ // (DeepSeek-R1-Distill-Qwen-7B with large system prompts) work correctly
33+
34+ // DeepSeek models typically use 4096 or 8192 context
35+ let deepseek_ctx = LlamaEngine :: calculate_adaptive_batch_size ( 4096 ) ;
36+ assert ! ( deepseek_ctx >= 4096 , "DeepSeek context should be supported" ) ;
37+
38+ // With large system prompts, we might need more batch capacity
39+ // The original issue had n_batch = 2048, which was insufficient
40+ assert ! ( deepseek_ctx > 2048 , "Batch size should exceed the problematic 2048 limit" ) ;
41+ }
42+
43+ #[ test]
44+ fn test_batch_size_reasonable_limits ( ) {
45+ // Ensure we don't create excessively large batch sizes that would waste memory
46+
47+ // Very large contexts should still be capped
48+ let huge_ctx = LlamaEngine :: calculate_adaptive_batch_size ( 32768 ) ;
49+ assert_eq ! ( huge_ctx, 8192 , "Huge contexts should be capped to prevent memory waste" ) ;
50+
51+ // Edge case: context exactly at cap
52+ let exact_cap = LlamaEngine :: calculate_adaptive_batch_size ( 8192 ) ;
53+ assert_eq ! ( exact_cap, 8192 , "Exact cap should be allowed" ) ;
54+ }
55+ }
0 commit comments