Kalosm

repository·main·Indexed 24 days ago

https://github.com/floneum/kalosm

An ecosystem of Rust crates for developing applications using local or remote AI models across text, audio, and vision modalities. It includes support for Llama text generation, structured generation with parsers, embedding-powered search with SurrealDB, Whisper-based audio transcription, voice activity detection, and image segmentation via SegmentAnything. The ecosystem also features Fusor ML, a WGPU-based ML runtime designed for high performance through kernel fusion.

Tokens
65.7K
Snippets
103
Records
359
Agent score
81%

What's inside kalosm

  1. Overview of Kalosm packages

    main

    Kalosm provides specialized interfaces for different modalities through three main packages:

    • kalosm::language: Handles text generation and embedding models. It includes tools for search databases and collecting text from websites, RSS feeds, and search engines.
    • kalosm::audio: Handles audio transcription. It supports microphone input, voice activity detection, and transcription using the whisper model.
    • kalosm::vision: Handles image segmentation. It supports the segment-anything model and integrates with the image crate.
  2. Overview of Fusor ML

    main

    Fusor ML is a WGPU-based Machine Learning (ML) runtime designed for high performance through kernel fusion. It enables ergonomic implementation of custom operations by fusing multiple operations into single kernels. It is intended to serve as the web and AMD runtime for the kalosm ecosystem once it reaches stability.

    Note: This project is currently NOT production ready.

  3. Overview of supported Kalosm models

    main

    Kalosm provides interfaces for various model modalities. Most models support quantization and GPU acceleration.

    ModelModalityDescription
    LlamaTextGeneral purpose language model (1b-70b)
    MistralTextGeneral purpose language model (7-13b)
    PhiTextSmall reasoning focused language model (2b-4b)
    WhisperAudioAudio transcription model (20MB-1GB)
    Segment AnythingImageImage segmentation model (50MB-400MB)
    BertTextText embedding model (100MB-1GB)
  4. Overview of Kalosm Sound

    main

    Kalosm Sound is a collection of audio models and utilities designed for the Kalosm framework. It provides capabilities for:

    • Voice Activity Detection (VAD): Identifying when speech is occurring in an audio stream.
    • Transcription: Converting audio streams into text using models like Whisper.
    • Audio Stream Transformation: Processing audio via various extensions for denoising, filtering, and chunking.
  5. Use Kalosm Llama for LLM inference and structured generation

    main

    Kalosm Llama provides the transformer implementation for Llama, Mistral, Phi, and Qwen models. It is the primary engine for running these models within the Kalosm ecosystem.

    Core Components

    • Llama struct: The main entrypoint for interacting with the models.
    • Llama::builder(): Used to configure and create a model instance.
    • ChatModelExt trait: Provides high-level methods like .chat() to start chat sessions or .task() to start specific tasks.
    • Parse macro: Enables structured generation by allowing you to define Rust types (structs and enums) that the model must adhere to when generating output.

    Structured Generation Workflow

    To force the model to output data in a specific format (like JSON), you can use the .with_constraints() method on a task. This requires implementing the Parse derive macro on your target data structures and passing a parser created via <Type as Parse>::new_parser().

    // Example of structured generation with constraints
    #[derive(Debug, Clone, Parse)]
    struct Pet {
        name: String,
        description: String,
        color: String,
        size: Size,
        diet: Diet,
    }
    
    // ... define enums with #[parse(rename = "...")] ...
    
    let task = llm
        .task("You generate realistic JSON placeholders")
        .with_constraints(Arc::new(<[Pet; 4] as Parse>::new_parser()));
    
    let stream = task.run(prompt);
  6. What is Fusor and when should I use it?

    main

    Fusor is a WGPU runtime designed for quantized ML inference. It is intended to be the backend for Kalosm (planned for version 0.5) to enable support for Web and AMD hardware.

    Key Features:

    • GGUF Support: Loads quantized models using the GGUF format.
    • Cross-Platform Acceleration: Uses WGPU to target Nvidia GPUs, AMD GPUs, and Metal (Apple).
    • Kernel Fusion: Uses a kernel fusion compiler to merge custom operation chains into a single optimized kernel, improving performance without manual shader writing.

    Warning: Fusor is currently in early development and is not ready for production use.

  7. Use structured generation to force specific output formats

    main

    Structured generation allows you to constrain a Task so that the model's output must conform to a specific format defined by a parser. This is useful for extracting data into typed structures or specific string patterns.

    To use structured generation, you must:

    1. Define a parser (via Parse derivation, combinators, or regex).
    2. Apply the parser to a task using .with_constraints(Arc::new(parser)).
    3. Await the task to receive the parsed data (if using derived or combinator parsers) or use the stream (if using a RegexParser).
  8. Subgroup coverage limitations in Lavapipe

    main

    The current macOS arm64 Lavapipe build reports a subgroup range of 4..=4.

    Because the conformance harness does not currently utilize VkPipelineShaderStageRequiredSubgroupSizeCreateInfo to request alternate subgroup widths, specific widths like 8, 16, 32, or 64 are not executed as real Vulkan subgroup widths during these tests. Coverage is limited to what Fusor/wgpu can execute on the adapter given its reported subgroup range.

  9. Transform audio streams with Kalosm Sound utilities

    main

    Kalosm Sound models operate on any type that implements AsyncSource. You can use MicInput::stream for live microphone input or any synchronous source implementing rodio::Source (such as .mp3 or .wav files).

    Available stream transformations include:

    • VoiceActivityDetectorExt::voice_activity_stream: Detects voice activity in the audio data.
    • DenoisedExt::denoise_and_detect_voice_activity: Denoises audio and then detects voice activity.
    • AsyncSourceTranscribeExt::transcribe: Chunks an audio stream based on voice activity and transcribes the resulting chunks.
    • VoiceActivityStreamExt::rechunk_voice_activity: Groups consecutive audio samples with high VAD probability into chunks.
    • VoiceActivityStreamExt::filter_voice_activity: Filters audio chunks based on voice activity.
    • TranscribeChunkedAudioStreamExt::transcribe: Transcribes an already chunked audio stream.
  10. How Sound Streams work in Kalosm

    main

    Kalosm Sound models operate on any type that implements the AsyncSource trait. You can ingest audio from various sources, including:

    • Real-time microphone input using MicInput::stream.
    • Synchronous audio files (like .mp3 or .wav) that implement the rodio::Source trait.
  11. Manage conversation state with ChatSession

    main

    The ChatSession trait manages the state of a text completion model by caching the history of messages fed to it. It is typically used alongside a ChatModel to maintain context across multiple turns in a conversation. You can access the underlying session from a chat instance using .session().

    let mut llm = Llama::new_chat().await.unwrap();
    let mut chat = llm.chat();
    // chat now manages a ChatSession internally
  12. Manage model state with TextCompletionSession

    main
    The TextCompletionSession trait is used to hold the state of a text completion model after it has been processed with specific text. It allows you to cache the context of a conversation or a sequence of prompts, which can then be used in conjunction with a TextCompletionModel to continue generation from that specific state without re-processing the entire history.