candle
candle copied to clipboard
[DRAFT] Add `candle-utils` helper crate for common patterns
Overview
This draft PR proposes adding a new candle-utils crate that provides higher-level abstractions for common patterns found throughout the Candle examples. The goal is to reduce boilerplate for common use cases.
Motivation
While working with Candle, I noticed several patterns that are common across many examples (and throughout the ecosystem - Mistral.rs, Text Embedding Inference, etc.). For example:
- Device selection logic - CPU/CUDA/Metal detection with fallbacks
- Model loading workflows - Tokenizer + config + weights loading from HF Hub
- Tokenization helpers - Batch encoding and attention mask creation
- Common tensor operations - L2 normalization and similar utilities
Questions
- Interest level: Are you open to this kind of higher-level utility crate in Candle?
- Scope: What utilities would be most valuable? I've focused on some of the patterns I've come across, but there may be others.
- API design: Any preferences on the module organization or function signature (builder pattern)? I'm happy to adjust based on your feedback / conventions / requirements.
- Integration: Should this be:
- Another crate in the Candle project (current draft)?
- Integrated into an existing crate like
candle-core,candle-transformers, etc.? - A separate
candle-utilsthird party crate?
Current Status
This is a very minimal viable implementation just to demonstrate the concept. If there's interest, I'm happy to iterate on this based on your feedback and requirements and keep working on this (tests, builders, more utils, check the examples for compatibility, etc.).
If this direction isn't aligned with your vision for Candle, no worries at all - I just wanted to check before investing more time in the implementation.
Thanks for considering this!