You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add comprehensive Testing section with Memory Leak Testing subsection
- Document how to run tests with AddressSanitizer
- Document Valgrind integration (make test-valgrind)
- List all 10 test scenarios covered by test-memory-leaks.cpp
- Include build commands, test execution instructions
- Document environment variables and CI integration
- Reference known issues (test-opt.cpp leak)
Addresses GitHub comment from @stephencornwell requesting README update.
Co-Authored-By: Stephen Cornwell <[email protected]>
The repository includes comprehensive memory leak regression tests to ensure proper memory management across various lifecycle scenarios. These tests go beyond the existing AddressSanitizer (ASan) integration by providing dedicated leak detection test suites.
550
+
551
+
**Running with AddressSanitizer:**
552
+
553
+
The primary memory leak detection mechanism uses AddressSanitizer, which is configured as a build option:
4. **Multiple contexts per model** - Creating multiple contexts from the same model (5 contexts)
599
+
5. **Sampler lifecycle** - Sampler creation, chain operations, and cleanup
600
+
6. **Batch operations** - Batch allocation and deallocation patterns
601
+
7. **KV cache clearing** - Memory clearing operations on contexts
602
+
8. **Threaded contexts** - Concurrent model usage with multiple threads
603
+
9. **Model load cancellation** - Cleanup when canceling model loading mid-process
604
+
10. **Error condition cleanup** - Proper cleanup when operations fail (e.g., invalid model path)
605
+
606
+
All tests follow proper cleanup order: sampler → context → model → backend.
607
+
608
+
**Environment Variables:**
609
+
610
+
- `LLAMACPP_TEST_MODELFILE` - Path to test model file (required for running tests)
611
+
612
+
**Continuous Integration:**
613
+
614
+
The GitHub Actions CI automatically runs all tests with all three sanitizers (ADDRESS, THREAD, UNDEFINED) on every pull request to catch memory issues before they reach production.
615
+
616
+
**Known Issues:**
617
+
618
+
- `test-opt.cpp` is currently disabled with `LLAMA_SANITIZE_ADDRESS` due to a known memory leak in `ggml_opt_alloc()` called within a loop (see `tests/test-opt.cpp:300`)
619
+
545
620
#### Seminal papers and background on the models
546
621
547
622
If your issue is with model generation quality, then please at least scan the following links and papers to understand the limitations of LLaMA models. This is especially important when choosing an appropriate model size and appreciating both the significant and subtle differences between LLaMA models and ChatGPT:
0 commit comments