mullama 0.1.0

Comprehensive Rust bindings for llama.cpp with memory-safe API and advanced features
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# Contributing to Mullama

Thank you for your interest in contributing to Mullama! We welcome contributions from the community and are excited to work with you to make Mullama the best Rust bindings for llama.cpp.

## ๐Ÿš€ Quick Start

1. **Fork** the repository
2. **Clone** your fork: `git clone --recurse-submodules https://github.com/yourusername/mullama.git`
3. **Create** a feature branch: `git checkout -b feature/amazing-feature`
4. **Make** your changes
5. **Test** your changes: `cargo test`
6. **Commit** your changes: `git commit -m 'Add amazing feature'`
7. **Push** to your branch: `git push origin feature/amazing-feature`
8. **Open** a Pull Request

## ๐Ÿ“‹ Development Setup

### Prerequisites

- **Rust 1.70+** with `cargo`
- **CMake 3.12+**
- **C++17 compiler** (GCC 8+, Clang 7+, or MSVC 2019+)
- **Git** with submodule support

### Development Dependencies

```bash
# Install development tools
cargo install cargo-watch
cargo install cargo-tarpaulin
cargo install cargo-clippy
cargo install rustfmt

# For documentation
cargo install mdbook
```

### Building

```bash
# Clone with submodules
git clone --recurse-submodules https://github.com/yourusername/mullama.git
cd mullama

# Build
cargo build

# Run tests
cargo test

# Run tests with coverage
cargo tarpaulin --out html
```

### Development Workflow

```bash
# Watch for changes and run tests
cargo watch -x test

# Run specific test suites
cargo test --test unit_tests
cargo test --test integration_tests
cargo test --test sampling_tests

# Check formatting
cargo fmt --check

# Run linter
cargo clippy -- -D warnings

# Build documentation
cargo doc --open
```

## ๐ŸŽฏ Areas for Contribution

### High Priority

- **๐Ÿงช Test Coverage**: Add more test cases, especially edge cases
- **๐Ÿ“š Documentation**: Improve guides, examples, and API docs
- **โšก Performance**: Optimize critical paths and memory usage
- **๐Ÿ”ง GPU Support**: Enhance CUDA, Metal, and ROCm integration
- **๐Ÿ› Bug Fixes**: Address issues and improve stability

### Medium Priority

- **โœจ New Features**: Implement additional llama.cpp functionality
- **๐Ÿ“ฆ Examples**: Create more real-world usage examples
- **๐Ÿ› ๏ธ Developer Tools**: Improve build system and debugging tools
- **๐Ÿ“Š Benchmarks**: Add comprehensive performance tests

### Lower Priority

- **๐ŸŽจ API Ergonomics**: Improve the developer experience
- **๐Ÿ“ฑ Platform Support**: Enhance compatibility across platforms
- **๐Ÿ” Profiling**: Add detailed performance profiling tools

## ๐Ÿ“ Contribution Guidelines

### Code Style

We follow standard Rust conventions:

```bash
# Format code
cargo fmt

# Check with clippy
cargo clippy -- -D warnings
```

**Key principles:**
- Use `snake_case` for functions and variables
- Use `PascalCase` for types and traits
- Prefer explicit types in public APIs
- Add comprehensive documentation to public items
- Follow the existing error handling patterns

### Documentation

All public APIs must be documented:

```rust
/// Brief description of the function.
///
/// Longer description explaining the behavior, parameters,
/// and return values in detail.
///
/// # Arguments
///
/// * `param1` - Description of parameter 1
/// * `param2` - Description of parameter 2
///
/// # Returns
///
/// Description of what the function returns.
///
/// # Errors
///
/// Description of when and what errors can occur.
///
/// # Examples
///
/// ```rust
/// use mullama::Model;
///
/// let model = Model::from_file("path/to/model.gguf")?;
/// ```
pub fn example_function(param1: &str, param2: i32) -> Result<String, MullamaError> {
    // Implementation
}
```

### Testing

All contributions should include appropriate tests:

#### Unit Tests
```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_basic_functionality() {
        // Test implementation
        assert_eq!(expected, actual);
    }

    #[test]
    fn test_error_conditions() {
        let result = function_that_should_fail();
        assert!(result.is_err());
    }
}
```

#### Integration Tests
Place integration tests in the `tests/` directory:

```rust
// tests/my_feature_tests.rs
use mullama::*;

#[test]
fn test_feature_integration() {
    // Test with actual models/contexts
}
```

### Error Handling

Use the existing error types consistently:

```rust
use mullama::MullamaError;

pub fn my_function() -> Result<T, MullamaError> {
    match some_operation() {
        Ok(value) => Ok(value),
        Err(_) => Err(MullamaError::OperationFailed("Descriptive message".to_string())),
    }
}
```

### Performance

- Profile performance-critical code
- Use `cargo bench` for benchmarks
- Avoid unnecessary allocations
- Consider memory usage impact
- Test with large models when relevant

## ๐Ÿงช Testing

### Running Tests

```bash
# Run all tests
cargo test

# Run specific test files
cargo test --test unit_tests
cargo test --test integration_tests
cargo test --test sampling_tests
cargo test --test error_tests
cargo test --test benchmark_tests

# Run tests with output
cargo test -- --nocapture

# Run tests matching a pattern
cargo test tokenize

# Run with coverage
cargo tarpaulin --out html
```

### Test Categories

1. **Unit Tests** (`src/lib.rs`, `src/*/mod.rs`)
   - Test individual functions and modules
   - Mock external dependencies
   - Fast execution

2. **Integration Tests** (`tests/integration_tests.rs`)
   - Test component interactions
   - Use real llama.cpp functionality
   - May require model files

3. **Performance Tests** (`tests/benchmark_tests.rs`)
   - Benchmark critical operations
   - Regression testing
   - Memory usage validation

4. **Error Tests** (`tests/error_tests.rs`)
   - Test error conditions
   - Edge cases and boundary conditions
   - Resource exhaustion scenarios

### Test Requirements

- **Fast**: Unit tests should run quickly
- **Reliable**: Tests should be deterministic
- **Isolated**: Tests shouldn't depend on external resources
- **Comprehensive**: Cover both success and error paths

## ๐Ÿ“š Documentation Standards

### Code Documentation

- **Public APIs**: Must have comprehensive rustdoc
- **Examples**: Include practical usage examples
- **Error Cases**: Document when and why errors occur
- **Performance**: Note performance characteristics

### Guide Documentation

- **Clear Structure**: Use consistent headings and formatting
- **Practical Examples**: Show real-world usage
- **Progressive Complexity**: Start simple, build up
- **Cross-references**: Link to related concepts

### Example Code

All examples should:
- Be runnable (when possible)
- Include error handling
- Show best practices
- Be well-commented

## ๐Ÿ”„ Pull Request Process

### Before Submitting

1. **Run Tests**: `cargo test`
2. **Check Formatting**: `cargo fmt --check`
3. **Run Linter**: `cargo clippy -- -D warnings`
4. **Update Documentation**: Add/update relevant docs
5. **Add Tests**: Include appropriate test coverage

### PR Description Template

```markdown
## Description
Brief description of what this PR does.

## Changes
- List of specific changes made
- Breaking changes (if any)
- New features added

## Testing
- How the changes were tested
- New tests added
- Performance impact (if any)

## Documentation
- Documentation updates made
- Examples added/updated

## Checklist
- [ ] Tests pass locally
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes (or documented)
```

### Review Process

1. **Automated Checks**: CI must pass
2. **Code Review**: At least one maintainer review
3. **Testing**: Comprehensive test coverage
4. **Documentation**: Appropriate documentation updates

## ๐Ÿ—๏ธ Architecture Guidelines

### Module Organization

```
src/
โ”œโ”€โ”€ lib.rs          # Public API exports
โ”œโ”€โ”€ model.rs        # Model loading and management
โ”œโ”€โ”€ context.rs      # Context and evaluation
โ”œโ”€โ”€ sampling.rs     # Sampling strategies
โ”œโ”€โ”€ batch.rs        # Batch processing
โ”œโ”€โ”€ sys.rs          # FFI bindings
โ”œโ”€โ”€ error.rs        # Error types
โ””โ”€โ”€ utils.rs        # Utility functions
```

### FFI Guidelines

- Keep unsafe code isolated in `sys.rs`
- Validate all inputs from C
- Handle null pointers gracefully
- Use proper error propagation
- Document safety requirements

### Memory Management

- Use RAII patterns consistently
- Implement proper Drop traits
- Avoid memory leaks
- Handle resource cleanup on errors
- Document lifetime requirements

## ๐Ÿ› Bug Reports

When reporting bugs, please include:

1. **Environment**: OS, Rust version, hardware
2. **Steps to Reproduce**: Minimal example
3. **Expected Behavior**: What should happen
4. **Actual Behavior**: What actually happens
5. **Logs/Errors**: Full error messages
6. **Model Information**: Model type, size, format

### Bug Report Template

```markdown
**Environment**
- OS: [e.g., Ubuntu 22.04, macOS 13.0, Windows 11]
- Rust version: [e.g., 1.70.0]
- Mullama version: [e.g., 0.1.0]
- Hardware: [e.g., CPU, GPU model]

**Description**
A clear description of the bug.

**Steps to Reproduce**
1. Load model X
2. Call function Y with parameters Z
3. Observe error

**Expected Behavior**
What you expected to happen.

**Actual Behavior**
What actually happened.

**Error Messages**
```
Full error output here
```

**Additional Context**
Any other relevant information.
```

## ๐Ÿš€ Feature Requests

For new features, please:

1. **Check Existing Issues**: Avoid duplicates
2. **Describe Use Case**: Why is this needed?
3. **Propose API**: What should the interface look like?
4. **Consider Impact**: Performance, compatibility, complexity
5. **Implementation Ideas**: How might it work?

## ๐Ÿ“ž Getting Help

- **๐Ÿ’ฌ Discussions**: [GitHub Discussions]https://github.com/username/mullama/discussions
- **๐Ÿ› Issues**: [GitHub Issues]https://github.com/username/mullama/issues
- **๐Ÿ“š Documentation**: [docs.rs/mullama]https://docs.rs/mullama
- **๐Ÿ“ง Email**: maintainers@mullama.dev

## ๐ŸŽ‰ Recognition

Contributors will be:
- Listed in the CONTRIBUTORS.md file
- Mentioned in release notes for significant contributions
- Invited to join the maintainer team for sustained contributions

## ๐Ÿ“„ License

By contributing to Mullama, you agree that your contributions will be licensed under the MIT License.

---

Thank you for contributing to Mullama! Together, we're building the best Rust bindings for llama.cpp. ๐Ÿฆ™โค๏ธ