Tag: LLM

  • Build Your Own and Free AI Health Assistant, Personalized Healthcare

    Build Your Own and Free AI Health Assistant, Personalized Healthcare

    Imagine having a 24/7 health companion that analyzes your medical history, tracks real-time vitals, and offers tailored advice—all while keeping your data private. This is the reality of AI health assistants, open-source tools merging artificial intelligence with healthcare to empower individuals and professionals alike. Let’s dive into how these systems work, their transformative benefits, and how you can build one using platforms like OpenHealthForAll 

    What Is an AI Health Assistant?

    An AI health assistant is a digital tool that leverages machine learning, natural language processing (NLP), and data analytics to provide personalized health insights. For example:

    • OpenHealth consolidates blood tests, wearable data, and family history into structured formats, enabling GPT-powered conversations about your health.
    • Aiden, another assistant, uses WhatsApp to deliver habit-building prompts based on anonymized data from Apple Health or Fitbit.

    These systems prioritize privacy, often running locally or using encryption to protect sensitive information.


    Why AI Health Assistants Matter: 5 Key Benefits

    1. Centralized Health Management
      Integrate wearables, lab reports, and EHRs into one platform. OpenHealth, for instance, parses blood tests and symptoms into actionable insights using LLMs like Claude or Gemini.
    2. Real-Time Anomaly Detection
      Projects like Kavya Prabahar’s virtual assistant use RNNs to flag abnormal heart rates or predict fractures from X-rays.
    3. Privacy-First Design
      Tools like Aiden anonymize data via Evervault and store records on blockchain (e.g., NearestDoctor’s smart contracts) to ensure compliance with regulations like HIPAA.
    4. Empathetic Patient Interaction
      Assistants like OpenHealth use emotion-aware AI to provide compassionate guidance, reducing anxiety for users managing chronic conditions.
    5. Cost-Effective Scalability
      Open-source frameworks like Google’s Open Health Stack (OHS) help developers build offline-capable solutions for low-resource regions, accelerating global healthcare access.

    Challenges and Ethical Considerations

    While promising, AI health assistants face hurdles:

    • Data Bias: Models trained on limited datasets may misdiagnose underrepresented groups.
    • Interoperability: Bridging EHR systems (e.g., HL7 FHIR) with AI requires standardization efforts like OHS.
    • Regulatory Compliance: Solutions must balance innovation with safety, as highlighted in Nature’s call for mandatory feedback loops in AI health tech.

    Build Your Own AI Health Assistant: A Developer’s Guide

    Step 1: Choose Your Stack

    • Data Parsing: Use OpenHealth’s Python-based parser (migrating to TypeScript soon) to structure inputs from wearables or lab reports.
    • AI Models: Integrate LLaMA or GPT-4 via APIs, or run Ollama locally for privacy.

    Step 2: Prioritize Security

    • Encrypt user data with Supabase or Evervault.
    • Implement blockchain for audit trails, as seen in NearestDoctor’s medical records system.

    Step 3: Start the setup

    Clone the Repository:

    git clone https://github.com/OpenHealthForAll/open-health.git
    cd open-health

    Setup and Run:

    # Copy environment file
    cp .env.example .env
    
    # Add API keys to .env file:
    # UPSTAGE_API_KEY - For parsing (You can get $10 credit without card registration by signing up at https://www.upstage.ai)
    # OPENAI_API_KEY - For enhanced parsing capabilities
    
    # Start the application using Docker Compose
    docker compose --env-file .env up

    For existing users, use:

    docker compose --env-file .env up --build
    1. Access OpenHealth: Open your browser and navigate to http://localhost:3000 to begin using OpenHealth.

    The Future of AI Health Assistants

    1. Decentralized AI Marketplaces: Platforms like Ocean Protocol could let users monetize health models securely.
    2. AI-Powered Diagnostics: Google’s Health AI Developer Foundations aim to simplify building diagnostic tools for conditions like diabetes.
    3. Global Accessibility: Initiatives like OHS workshops in Kenya and India are democratizing AI health tech.

    Your Next Step

    • Contribute to OpenHealth’s GitHub repo to enhance its multilingual support.
  • How to Install and Run Virtuoso-Medium-v2 Locally: A Step-by-Step Guide

    How to Install and Run Virtuoso-Medium-v2 Locally: A Step-by-Step Guide

    Virtuoso-Medium-v2 is here, Are you ready to harness the power of Virtuoso-Medium-v2 , the next-generation 32-billion-parameter language model? Whether you’re building advanced chatbots, automating workflows, or diving into research simulations, this guide will walk you through installing and running Virtuoso-Medium-v2 on your local machine. Let’s get started!

    Virtuoso-Medium-v2

    Why Choose Virtuoso-Medium-v2?

    Before we dive into the installation process, let’s briefly understand why Virtuoso-Medium-v2 stands out:

    • Distilled from Deepseek-v3 : With over 5 billion tokens worth of logits, it delivers unparalleled performance in technical queries, code generation, and mathematical problem-solving.
    • Cross-Architecture Compatibility : Thanks to “tokenizer surgery,” it integrates seamlessly with Qwen and Deepseek tokenizers.
    • Apache-2.0 License : Use it freely for commercial or non-commercial projects.

    Now that you know its capabilities, let’s set it up locally.

    Prerequisites

    Before installing Virtuoso-Medium-v2, ensure your system meets the following requirements:

    1. Hardware :
      • GPU with at least 24GB VRAM (recommended for optimal performance).
      • Sufficient disk space (~50GB for model files).
    2. Software :
      • Python 3.8 or higher.
      • PyTorch installed (pip install torch).
      • Hugging Face transformers library (pip install transformers).

    Step 1: Download the Model

    The first step is to download the Virtuoso-Medium-v2 model from Hugging Face. Open your terminal and run the following commands:

    # Install necessary libraries
    pip install transformers torch
    
    # Clone the model repository
    from transformers import AutoTokenizer, AutoModelForCausalLM
    
    model_name = "arcee-ai/Virtuoso-Medium-v2"
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)

    This will fetch the model and tokenizer directly from Hugging Face.


    Step 2: Prepare Your Environment

    Ensure your environment is configured correctly:
    1. Set up a virtual environment to avoid dependency conflicts:

    python -m venv virtuoso-env
    source virtuoso-env/bin/activate  # On Windows: virtuoso-env\Scripts\activate

    2. Install additional dependencies if needed:

    pip install accelerate

    Step 3: Run the Model

    Once the model is downloaded, you can test it with a simple prompt. Here’s an example script:

    from transformers import AutoTokenizer, AutoModelForCausalLM
    
    # Load the model and tokenizer
    model_name = "arcee-ai/Virtuoso-Medium-v2"
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(model_name)
    
    # Define your input prompt
    prompt = "Explain the concept of quantum entanglement in simple terms."
    inputs = tokenizer(prompt, return_tensors="pt")
    
    # Generate output
    outputs = model.generate(**inputs, max_new_tokens=150)
    print(tokenizer.decode(outputs[0], skip_special_tokens=True))

    Run the script, and you’ll see the model generate a concise explanation of quantum entanglement!

    Step 4: Optimize Performance

    To maximize performance:

    Use quantization techniques to reduce memory usage.

    Enable GPU acceleration by setting device_map="auto" during model loading:

    model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")

    Troubleshooting Tips

    • Out of Memory Errors : Reduce the max_new_tokens parameter or use quantized versions of the model.
    • Slow Inference : Ensure your GPU drivers are updated and CUDA is properly configured.

    With Virtuoso-Medium-v2 installed locally, you’re now equipped to build cutting-edge AI applications. Whether you’re developing enterprise tools or exploring STEM education, this model’s advanced reasoning capabilities will elevate your projects.

    Ready to take the next step? Experiment with Virtuoso-Medium-v2 today and share your experiences with the community! For more details, visit the official Hugging Face repository .

  • OpenAI o3-mini: Powerful, Fast, and Cost-Efficient for STEM Reasoning

    OpenAI o3-mini: Powerful, Fast, and Cost-Efficient for STEM Reasoning

    Exciting news from OpenAI—the highly anticipated o3-mini model is now available in ChatGPT and the API, offering groundbreaking capabilities for a wide range of use cases, particularly in science, math, and coding. First previewed in December 2024, o3-mini is designed to push the boundaries of what small models can achieve while keeping costs low and maintaining the fast response times that users have come to expect from o1-mini.

    Key Features of OpenAI o3-mini:

    🔹 Next-Level Reasoning for STEM Tasks
    o3-mini delivers exceptional STEM reasoning performance, with particular strength in science, math, and coding. It maintains the cost efficiency and low latency of its predecessor, o1-mini, but packs a much stronger punch in terms of reasoning power and accuracy.

    🔹 Developer-Friendly Features
    For developers, o3-mini introduces a host of highly-requested features:

    • Function Calling
    • Structured Outputs
    • Developer Messages
      These features make o3-mini production-ready right out of the gate. Additionally, developers can select from three reasoning effort options—low, medium, and high—allowing for fine-tuned control over performance. Whether you’re prioritizing speed or accuracy, o3-mini has you covered.

    🔹 Search Integration for Up-to-Date Answers
    For the first time, o3-mini works with search, enabling it to provide up-to-date answers along with links to relevant web sources. This integration is part of OpenAI’s ongoing effort to incorporate real-time search across their reasoning models, and while it’s still in an early prototype stage, it’s a step towards an even smarter, more responsive model.

    🔹 Enhanced Access for Paid Users
    Pro, Team, and Plus users will have triple the rate limits compared to o1-mini, with up to 150 messages per day instead of the 50 available on the earlier model. Plus, all paid users can select o3-mini-high, which offers a higher-intelligence version with slightly longer response times, ensuring Pro users have unlimited access to both o3-mini and o3-mini-high.

    🔹 Free Users Can Try o3-mini!
    For the first time, free users can also explore o3-mini in ChatGPT by simply selecting the ‘Reason’ button in the message composer or regenerating a response. This brings access to high-performance reasoning capabilities previously only available to paid users.

    🔹 Optimized for Precision & Speed
    o3-mini is optimized for technical domains, where precision and speed are key. When set to medium reasoning effort, it delivers the same high performance as o1 on complex tasks but with much faster response times. In fact, evaluations show that o3-mini produces clearer, more accurate answers with a 39% reduction in major errors compared to o1-mini.


    A Model Built for Technical Excellence

    Whether you’re tackling challenging problems in math, coding, or science, o3-mini is designed to give you faster, more precise results. Expert testers have found that o3-mini beats o1-mini in 56% of cases, particularly when it comes to real-world, difficult questions like those found in AIME and GPQA evaluations. It’s a clear choice for tasks that require a blend of intelligence and speed.


    Rolling Out to Developers and Users

    Starting today, o3-mini is rolling out in the Chat Completions API, Assistants API, and Batch API to developers in API usage tiers 3-5. ChatGPT Plus, Team, and Pro users have access starting now, with Enterprise access coming in February.

    This model will replace o1-mini in the model picker, making it the go-to choice for STEM reasoning, logical problem-solving, and coding tasks.


    OpenAI o3-mini marks a major leap in small model capabilities—delivering both powerful reasoning and cost-efficiency in one package. As OpenAI continues to refine and optimize these models, o3-mini sets a new standard for fast, intelligent, and reliable solutions for developers and users alike.

    Competition Math (AIME 2024)

    Competition Math (AIME 2024)

    Mathematics: With low reasoning effort, OpenAI o3-mini achieves comparable performance with OpenAI o1-mini, while with medium effort, o3-mini achieves comparable performance with o1. Meanwhile, with high reasoning effort, o3-mini outperforms both OpenAI o1-mini and OpenAI o1, where the gray shaded regions show the performance of majority vote (consensus) with 64 samples.

    PhD-level Science Questions (GPQA Diamond)

    PhD-level Science Questions (GPQA Diamond)

    PhD-level science: On PhD-level biology, chemistry, and physics questions, with low reasoning effort, OpenAI o3-mini achieves performance above OpenAI o1-mini. With high effort, o3-mini achieves comparable performance with o1.

    FrontierMath

    A black grid with multiple rows and columns, separated by thin white lines, creating a structured and organized layout.

    Research-level mathematics: OpenAI o3-mini with high reasoning performs better than its predecessor on FrontierMath. On FrontierMath, when prompted to use a Python tool, o3-mini with high reasoning effort solves over 32% of problems on the first attempt, including more than 28% of the challenging (T3) problems. These numbers are provisional, and the chart above shows performance without tools or a calculator.

    Competition Code (Codeforces)

    Competition coding: On Codeforces competitive programming, OpenAI o3-mini achieves progressively higher Elo scores with increased reasoning effort, all outperforming o1-mini. With medium reasoning effort, it matches o1’s performance.

    Software Engineering (SWE-bench Verified)

    Software Engineering (SWE-bench Verified)

    Software engineering: o3-mini is our highest performing released model on SWEbench-verified. For additional datapoints on SWE-bench Verified results with high reasoning effort, including with the open-source Agentless scaffold (39%) and an internal tools scaffold (61%), see our system card⁠.

    LiveBench Coding

    The table compares AI models on coding tasks, showing performance metrics and evaluation scores. It highlights differences in accuracy and efficiency, with some models outperforming others in specific benchmarks.

    LiveBench coding: OpenAI o3-mini surpasses o1-high even at medium reasoning effort, highlighting its efficiency in coding tasks. At high reasoning effort, o3-mini further extends its lead, achieving significantly stronger performance across key metrics.

    General knowledge

    The table titled "Category Evals" compares AI models across different evaluation categories, showing performance metrics. It highlights differences in accuracy, efficiency, and effectiveness, with some models outperforming others in specific tasks.

    General knowledge: o3-mini outperforms o1-mini in knowledge evaluations across general knowledge domains.

    Model speed and performance

    With intelligence comparable to OpenAI o1, OpenAI o3-mini delivers faster performance and improved efficiency. Beyond the STEM evaluations highlighted above, o3-mini demonstrates superior results in additional math and factuality evaluations with medium reasoning effort. In A/B testing, o3-mini delivered responses 24% faster than o1-mini, with an average response time of 7.7 seconds compared to 10.16 seconds.

    Explore more and try it for yourself: OpenAI o3-mini Announcement

  • Qwen2.5-Max: Alibaba’s New AI Model Outperforms DeepSeek, GPT-4o, and Claude Sonnet

    Qwen2.5-Max: Alibaba’s New AI Model Outperforms DeepSeek, GPT-4o, and Claude Sonnet

    In the rapidly evolving landscape of Artificial Intelligence, a new contender has emerged, shaking up the competition. Alibaba has just unveiled Qwen2.5-Max, a cutting-edge AI model that is setting new benchmarks for performance and capabilities. This model not only rivals but also surpasses leading models like DeepSeek V3, GPT-4o, and Claude Sonnet across a range of key evaluations. Qwen2.5-Max is not just another AI model; it’s a leap forward in AI technology.

    What Makes Qwen2.5-Max a Game-Changer?

    Qwen2.5-Max is packed with features that make it a true game-changer in the AI space:

    • Code Execution & Debugging: It doesn’t just generate code; it runs and debugs it in real-time. This capability is crucial for developers who need to test and refine their code quickly.
    • Ultra-Precise Image Generation: Forget generic AI art; Qwen2.5-Max produces highly detailed, instruction-following images, opening up new possibilities in creative fields.
    • Faster AI Video Generation: This model creates video much faster than the 90% of existing AI tools
    • Web Search & Knowledge Synthesis: The model can perform real-time searches, gather data, and summarize findings, making it a powerful tool for research and analysis.
    • Vision Capabilities: Upload PDFs, images, and documents, and Qwen2.5-Max will read, analyze, and extract valuable insights instantly, enhancing its applicability in document-heavy tasks.

    Technical Details

    Qwen2.5-Max is a large-scale Mixture-of-Experts (MoE) model that has been pre-trained on over 20 trillion tokens. Following pre-training, the model was fine-tuned using Supervised Fine-Tuning (SFT) and Reinforcement Learning from Human Feedback (RLHF), further enhancing its capabilities.

    Performance Benchmarks

    The performance of Qwen2.5-Max is nothing short of impressive. It has been evaluated across several benchmarks, including:

    • MMLU-Pro: Testing its knowledge through college-level problems.
    • LiveCodeBench: Assessing its coding skills.
    • LiveBench: Measuring its general capabilities.
    • Arena-Hard: Evaluating its alignment with human preferences.

    Qwen2.5-Max significantly outperforms DeepSeek V3 in benchmarks such as Arena-Hard, LiveBench, LiveCodeBench, and GPQA-Diamond. While also showing competitive performance in other assessments like MMLU-Pro. The base models also show significant advantages across most benchmarks when compared to DeepSeek V3, Llama-3.1-405B, and Qwen2.5-72B.

    How to Use Qwen2.5-Max

    Qwen2.5-Max is now available on Qwen Chat, where you can interact with the model directly. It is also accessible via an API through Alibaba Cloud. Here is the steps to use the API:

    1. Register an Alibaba Cloud account and activate the Alibaba Cloud Model Studio service.
    2. Navigate to the console and create an API key.
    3. Since the APIs are OpenAI-API compatible, you can use them as you would with OpenAI APIs.

    Here is an example of using Qwen2.5-Max in Python:

    from openai import OpenAI
    import os
    
    client = OpenAI(
        api_key=os.getenv("API_KEY"),
        base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
    )
    
    completion = client.chat.completions.create(
        model="qwen-max-2025-01-25",
        messages=[
          {'role': 'system', 'content': 'You are a helpful assistant.'},
          {'role': 'user', 'content': 'Which number is larger, 9.11 or 9.8?'}
        ]
    )
    
    print(completion.choices[0].message)

    Future Implications

    Alibaba’s commitment to continuous research and development is evident in Qwen2.5-Max. The company is dedicated to enhancing the thinking and reasoning capabilities of LLMs through innovative scaled reinforcement learning. This approach aims to unlock new frontiers in AI by potentially enabling AI models to surpass human intelligence.

    Citation

    If you find Qwen2.5-Max helpful, please cite the following paper:

    @article{qwen25,
      title={Qwen2.5 technical report},
      author={Qwen Team},
      journal={arXiv preprint arXiv:2412.15115},
      year={2024}
    }

    Qwen2.5-Max represents a significant advancement in AI technology. Its superior performance across multiple benchmarks and its diverse range of capabilities make it a crucial tool for various applications. As Alibaba continues to develop and refine this model, we can expect even more groundbreaking innovations in the future.

  • Deploy an uncensored DeepSeek R1 model on Google Cloud Run

    Deploy an uncensored DeepSeek R1 model on Google Cloud Run

    DeepSeek R1 Distill: Complete Tutorial for Deployment & Fine-Tuning

    Are you eager to explore the capabilities of the DeepSeek R1 Distill model? This guide provides a comprehensive, step-by-step approach to deploying the uncensored DeepSeek R1 Distill model to Google Cloud Run with GPU support, and also walks you through a practical fine-tuning process. The tutorial is broken down into the following sections:

    Deploy uncensored DeepSeek model
    • Environment Setup
    • FastAPI Inference Server
    • Docker Configuration
    • Google Cloud Run Deployment
    • Fine-Tuning Pipeline

    Let’s dive in and get started.

    1. Environment Setup

    Before deploying and fine-tuning, make sure you have the required tools installed and configured.

    1.1 Install Required Tools

    • Python 3.9+
    • pip: For Python package installation
    • Docker: For containerization
    • Google Cloud CLI: For deployment

    Install Google Cloud CLI (Ubuntu/Debian):
    Follow the official Google Cloud CLI installation guide to install gcloud.

    1.2 Authenticate with Google Cloud

    Run the following commands to initialize and authenticate with Google Cloud:

    gcloud init
    gcloud auth application-default login

    Ensure you have an active Google Cloud project with Cloud Run, Compute Engine, and Container Registry/Artifact Registry enabled.

    2. FastAPI Inference Server

    We’ll create a minimal FastAPI application that serves two main endpoints:

    • /v1/inference: For model inference.
    • /v1/finetune: For uploading fine-tuning data (JSONL).

    Create a file named main.py with the following content:

    # main.py
    from fastapi import FastAPI, File, UploadFile
    from fastapi.responses import JSONResponse
    from pydantic import BaseModel
    import json
    
    import litellm  # Minimalistic LLM library
    
    app = FastAPI()
    
    class InferenceRequest(BaseModel):
        prompt: str
        max_tokens: int = 512
    
    @app.post("/v1/inference")
    async def inference(request: InferenceRequest):
        """
        Inference endpoint using deepseek-r1-distill-7b (uncensored).
        """
        response = litellm.completion(
            model="deepseek/deepseek-r1-distill-7b",
            messages=[{"role": "user", "content": request.prompt}],
            max_tokens=request.max_tokens
        )
        return JSONResponse(content=response)
    
    @app.post("/v1/finetune")
    async def finetune(file: UploadFile = File(...)):
        """
        Fine-tune endpoint that accepts a JSONL file.
        """
        if not file.filename.endswith('.jsonl'):
            return JSONResponse(
                status_code=400,
                content={"error": "Only .jsonl files are accepted for fine-tuning"}
            )
    
        # Read lines from uploaded file
        data = [json.loads(line) for line in file.file]
    
        # Perform or schedule a fine-tuning job here (simplified placeholder)
        # You can integrate with your training pipeline below.
        
        return JSONResponse(content={"status": "Fine-tuning request received", "samples": len(data)})

    3. Docker Configuration

    To containerize the application, create a requirements.txt file:

    fastapi
    uvicorn
    litellm
    pydantic
    transformers
    datasets
    accelerate
    trl
    torch

    And create a Dockerfile:

    # Dockerfile
    FROM nvidia/cuda:12.0.0-base-ubuntu22.04
    
    # Install basic dependencies
    RUN apt-get update && apt-get install -y python3 python3-pip
    
    # Create app directory
    WORKDIR /app
    
    # Copy requirements and install
    COPY requirements.txt .
    RUN pip3 install --upgrade pip
    RUN pip3 install --no-cache-dir -r requirements.txt
    
    # Copy code
    COPY . .
    
    # Expose port 8080 for Cloud Run
    EXPOSE 8080
    
    # Start server
    CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

    4. Deploy to Google Cloud Run with GPU

    4.1 Enable GPU on Cloud Run

    Make sure your Google Cloud project has a GPU quota available, such as nvidia-l4.

    4.2 Build and Deploy

    Run this command from your project directory to deploy the application to Cloud Run:

    gcloud run deploy deepseek-uncensored \
        --source . \
        --region us-central1 \
        --platform managed \
        --gpu 1 \
        --gpu-type nvidia-l4 \
        --memory 16Gi \
        --cpu 4 \
        --allow-unauthenticated

    This command builds the Docker image, deploys it to Cloud Run with one nvidia-l4 GPU, allocates 16 GiB memory and 4 CPU cores, and exposes the service publicly (no authentication).

    5. Fine-Tuning Pipeline

    This section will guide you through a basic four-stage fine-tuning pipeline similar to DeepSeek R1’s training approach.

    5.1 Directory Structure Example

    .
    ├── main.py
    ├── finetune_pipeline.py
    ├── cold_start_data.jsonl
    ├── reasoning_data.jsonl
    ├── data_collection.jsonl
    ├── final_data.jsonl
    ├── requirements.txt
    └── Dockerfile

    Replace the .jsonl files with your actual training data.

    5.2 Fine-Tuning Code: finetune_pipeline.py

    Create a finetune_pipeline.py file with the following code:

    # finetune_pipeline.py
    
    import os
    import torch
    from transformers import (AutoModelForCausalLM, AutoTokenizer,
                              Trainer, TrainingArguments)
    from datasets import load_dataset
    
    from trl import PPOTrainer, PPOConfig, AutoModelForCausalLMWithValueHead
    from transformers import pipeline, AutoModel
    
    
    # 1. Cold Start Phase
    def cold_start_finetune(
        base_model="deepseek-ai/deepseek-r1-distill-7b",
        train_file="cold_start_data.jsonl",
        output_dir="cold_start_finetuned_model"
    ):
        # Load model and tokenizer
        model = AutoModelForCausalLM.from_pretrained(base_model)
        tokenizer = AutoTokenizer.from_pretrained(base_model)
    
        # Load dataset
        dataset = load_dataset("json", data_files=train_file, split="train")
    
        # Simple tokenization function
        def tokenize_function(example):
            return tokenizer(
                example["prompt"] + "\n" + example["completion"],
                truncation=True,
                max_length=512
            )
    
        dataset = dataset.map(tokenize_function, batched=True)
        dataset = dataset.shuffle()
    
        # Define training arguments
        training_args = TrainingArguments(
            output_dir=output_dir,
            num_train_epochs=1,
            per_device_train_batch_size=2,
            gradient_accumulation_steps=4,
            save_steps=50,
            logging_steps=50,
            learning_rate=5e-5
        )
    
        # Trainer
        trainer = Trainer(
            model=model,
            args=training_args,
            train_dataset=dataset
        )
    
        trainer.train()
        trainer.save_model(output_dir)
        tokenizer.save_pretrained(output_dir)
        return output_dir
    
    
    # 2. Reasoning RL Training
    def reasoning_rl_training(
        cold_start_model_dir="cold_start_finetuned_model",
        train_file="reasoning_data.jsonl",
        output_dir="reasoning_rl_model"
    ):
        # Config for PPO
        config = PPOConfig(
            batch_size=16,
            learning_rate=1e-5,
            log_with=None,  # or 'wandb'
            mini_batch_size=4
        )
    
        # Load model and tokenizer
        model = AutoModelForCausalLMWithValueHead.from_pretrained(cold_start_model_dir)
        tokenizer = AutoTokenizer.from_pretrained(cold_start_model_dir)
    
        # Create a PPO trainer
        ppo_trainer = PPOTrainer(
            config,
            model,
            tokenizer=tokenizer,
        )
    
        # Load dataset
        dataset = load_dataset("json", data_files=train_file, split="train")
    
        # Simple RL loop (pseudo-coded for brevity)
        for sample in dataset:
            prompt = sample["prompt"]
            desired_answer = sample["completion"]  # For reward calculation
    
            # Generate response
            query_tensors = tokenizer.encode(prompt, return_tensors="pt")
            response_tensors = ppo_trainer.generate(query_tensors, max_new_tokens=50)
            response_text = tokenizer.decode(response_tensors[0], skip_special_tokens=True)
    
            # Calculate reward (simplistic: measure overlap or correctness)
            reward = 1.0 if desired_answer in response_text else -1.0
    
            # Run a PPO step
            ppo_trainer.step([query_tensors[0]], [response_tensors[0]], [reward])
    
        model.save_pretrained(output_dir)
        tokenizer.save_pretrained(output_dir)
        return output_dir
    
    
    # 3. Data Collection
    def collect_data(
        rl_model_dir="reasoning_rl_model",
        num_samples=1000,
        output_file="data_collection.jsonl"
    ):
        """
        Example data collection: generate completions from the RL model.
        This is a simple version that just uses random prompts or a given file of prompts.
        """
        tokenizer = AutoTokenizer.from_pretrained(rl_model_dir)
        model = AutoModelForCausalLM.from_pretrained(rl_model_dir)
    
        # Suppose we have some random prompts:
        prompts = [
            "Explain quantum entanglement",
            "Summarize the plot of 1984 by George Orwell",
            # ... add or load from a prompt file ...
        ]
    
        collected = []
        for i in range(num_samples):
            prompt = prompts[i % len(prompts)]
            inputs = tokenizer(prompt, return_tensors="pt")
            outputs = model.generate(**inputs, max_new_tokens=50)
            completion = tokenizer.decode(outputs[0], skip_special_tokens=True)
            collected.append({"prompt": prompt, "completion": completion})
    
        # Save to JSONL
        with open(output_file, "w") as f:
            for item in collected:
                f.write(f"{item}\n")
    
        return output_file
    
    
    # 4. Final RL Phase
    def final_rl_phase(
        rl_model_dir="reasoning_rl_model",
        final_data="final_data.jsonl",
        output_dir="final_rl_model"
    ):
        """
        Another RL phase using a new dataset or adding human feedback.
        This is a simplified approach similar to the reasoning RL training step.
        """
        config = PPOConfig(
            batch_size=16,
            learning_rate=1e-5,
            log_with=None,
            mini_batch_size=4
        )
    
        model = AutoModelForCausalLMWithValueHead.from_pretrained(rl_model_dir)
        tokenizer = AutoTokenizer.from_pretrained(rl_model_dir)
        ppo_trainer = PPOTrainer(config, model, tokenizer=tokenizer)
    
        dataset = load_dataset("json", data_files=final_data, split="train")
    
        for sample in dataset:
            prompt = sample["prompt"]
            desired_answer = sample["completion"]
            query_tensors = tokenizer.encode(prompt, return_tensors="pt")
            response_tensors = ppo_trainer.generate(query_tensors, max_new_tokens=50)
            response_text = tokenizer.decode(response_tensors[0], skip_special_tokens=True)
    
            reward = 1.0 if desired_answer in response_text else 0.0
            ppo_trainer.step([query_tensors[0]], [response_tensors[0]], [reward])
    
        model.save_pretrained(output_dir)
        tokenizer.save_pretrained(output_dir)
        return output_dir
    
    
    # END-TO-END PIPELINE EXAMPLE
    if __name__ == "__main__":
        # 1) Cold Start
        cold_start_out = cold_start_finetune(
            base_model="deepseek-ai/deepseek-r1-distill-7b",
            train_file="cold_start_data.jsonl",
            output_dir="cold_start_finetuned_model"
        )
    
        # 2) Reasoning RL
        reasoning_rl_out = reasoning_rl_training(
            cold_start_model_dir=cold_start_out,
            train_file="reasoning_data.jsonl",
            output_dir="reasoning_rl_model"
        )
    
        # 3) Data Collection
        data_collection_out = collect_data(
            rl_model_dir=reasoning_rl_out,
            num_samples=100,
            output_file="data_collection.jsonl"
        )
    
        # 4) Final RL Phase
        final_rl_out = final_rl_phase(
            rl_model_dir=reasoning_rl_out,
            final_data="final_data.jsonl",
            output_dir="final_rl_model"
        )
    
        print("All done! Final model stored in:", final_rl_out)

    Usage Overview

    1. Upload Your Data:
      • Prepare cold_start_data.jsonl, reasoning_data.jsonl, final_data.jsonl, etc.
      • Each line should be a JSON object with “prompt” and “completion” keys.
    2. Run the Pipeline Locally:
    python3 finetune_pipeline.py

    This creates directories like cold_start_finetuned_model, reasoning_rl_model, and final_rl_model.

    1. Deploy:
      • Build and push via gcloud run deploy.
    2. Inference:
      • After deployment, send a POST request to your Cloud Run service:
    import requests
    
    url = "https://<YOUR-CLOUD-RUN-URL>/v1/inference"
    data = {"prompt": "Tell me about quantum physics", "max_tokens": 100}
    response = requests.post(url, json=data)
    print(response.json())

    Fine-Tuning via Endpoint:

    • Upload new data for fine-tuning:
    import requests
    
    url = "https://<YOUR-CLOUD-RUN-URL>/v1/finetune"
    with open("new_training_data.jsonl", "rb") as f:
        r = requests.post(url, files={"file": ("new_training_data.jsonl", f)})
    print(r.json())

    This tutorial has provided an end-to-end pipeline for deploying and fine-tuning the DeepSeek R1 Distill model. You’ve learned how to:

    • Deploy a FastAPI server with Docker and GPU support on Google Cloud Run.
    • Fine-tune the model in four stages: Cold Start, Reasoning RL, Data Collection, and Final RL.
    • Use TRL (PPO) for basic RL-based training loops.

    Disclaimer: Deploying uncensored models has ethical and legal implications. Make sure to comply with relevant laws, policies, and usage guidelines.

    This comprehensive guide should equip you with the knowledge to start deploying and fine-tuning the DeepSeek R1 Distill model.

  • AI Agents by Google: Revolutionizing AI with Reasoning and Tools

    AI Agents by Google: Revolutionizing AI with Reasoning and Tools

    Artificial Intelligence is rapidly changing, and AI Agents by Google are at the forefront. These aren’t typical AI models. Instead, they are complex systems. They can reason, make logical decisions, and interact with the world using tools. This article explores what makes them special. Furthermore, it will examine how they are changing AI applications.

    Understanding AI Agents

    AI Agents by Google

    Essentially, AI Agents by Google are applications. The aim of AI Agents to achieve goals. They do this by observing their environment. They also use available tools. Unlike basic AI, agents are autonomous. They act independently. Moreover, they proactively make decisions. This helps them meet objectives, even without direct instructions. This is possible through their cognitive architecture, which includes three key parts:

    • The Model: This is the core language model. It is the central decision-maker. It uses reasoning frameworks like ReAct. Also, it uses Chain-of-Thought and Tree-of-Thoughts.
    • The Tools: These are crucial for external interaction. They allow the agent to connect to real-time data and services. For example, APIs can be used. They bridge the gap between internal knowledge and outside resources.
    • The Orchestration Layer: This layer manages the agent’s process. It determines how it takes in data. Then, it reasons internally. Finally, it informs the next action or decision in a continuous cycle.

    AI Agents vs. Traditional AI Models

    Traditional AI models have limitations. They are restricted by training data. They perform single inferences. In contrast, AI Agents by Google overcome these limits. They do this through several capabilities:

    • External System Access: They connect to external systems via tools. Thus, they interact with real-time data.
    • Session History Management: Agents track and manage session history. This enables multi-turn interactions with context.
    • Native Tool Implementation: They include built-in tools. This allows seamless execution of external tasks.
    • Cognitive Architectures: They utilize advanced frameworks. For instance, they use CoT and ReAct for reasoning.

    The Role of Tools: Extensions, Functions, and Data Stores

    AI Agents by Google interact with the outside world through three key tools:

    Extensions

    These tools bridge agents and APIs. They allow agents to use APIs to carry out actions through examples. For instance, they can use the Google Flights API. Extensions run on the agent-side. They are designed to make integrations scalable and strong.

    Functions

    Functions are self-contained code modules. Models use them for specific tasks. Unlike Extensions, these run on the client side. They don’t directly interact with APIs. This gives developers greater control over data flow and system execution.

    Data Stores

    Data Stores enable agents to access diverse data. This includes structured and unstructured data from various sources. For instance, they can access websites, PDFs, and databases. This dynamic interaction with current data enhances the model’s knowledge. Furthermore, it aids applications using Retrieval Augmented Generation (RAG).

    Improving Agent Performance

    To get the best results, AI Agents need targeted learning. These methods include:

    • In-context learning: Examples provided during inference let the model learn “on-the-fly.”
    • Retrieval-based in-context learning: External memory enhances this process. It provides more relevant examples.
    • Fine-tuning based learning: Pre-training the model is key. This improves its understanding of tools. Moreover, it improves its ability to know when to use them.

    Getting Started with AI Agents

    If you’re interested in building with AI Agents, consider using libraries like LangChain. Also, you might use platforms such as Google’s Vertex AI. LangChain helps users ‘chain’ sequences of logic and tool calls. Meanwhile, Vertex AI offers a managed environment. It supports building and deploying production-ready agents.

    AI Agents by Google are transforming AI. They go beyond traditional limits. They can reason, use tools, and interact with the external world. Therefore, they are a major step forward. They create more flexible and capable AI systems. As these agents evolve, their ability to solve complex problems will also grow. In addition, their capacity to drive real-world value will expand.

    Read More on the AI Agents by Google Whitepaper by Google.

  • Free, Open Source Realtime 3D Model: SPAR3D by Stability AI

    Realtime 3D model, Stability AI is revolutionizing the world of 3D content creation with its latest offering: SPAR3D, a groundbreaking free and open-source realtime 3D model. This model enables users to generate, edit, and interact with 3D objects from single images in real-time, combining impressive speed with unparalleled control. SPAR3D is not just a 3D model; it’s a comprehensive tool designed to transform 3D prototyping for game developers, product designers, environment builders, and anyone needing high-quality 3D assets.

    What is SPAR3D?

    SPAR3D (Stable Point Aware 3D) is a state-of-the-art 3D reconstruction model that achieves high-quality 3D mesh generation from single-view images, in near real-time. Unlike traditional 3D modeling methods, SPAR3D uniquely combines precise point cloud sampling with advanced mesh generation. What sets SPAR3D apart is its support for real-time editing, allowing users to make on-the-fly adjustments and modifications to 3D objects. Furthermore, this is available as free and open source under the Stability AI Community License.

    Key Features and Benefits of SPAR3D

    SPAR3D provides several significant advantages over other 3D modeling techniques:

    • Real-Time Editing: Allows users to directly manipulate the 3D model by editing the point cloud, deleting, duplicating, stretching, and even recoloring points. This level of control is unmatched by other methods.
    • Complete Structure Prediction: Generates not only the visible surfaces from an input image, but also accurately predicts the full 360-degree view, including traditionally hidden surfaces on the back of the object. This gives a complete picture of the 3D object.
    • Lightning-Fast Generation: Converts edited point clouds into final 3D meshes in just 0.3 seconds, enabling seamless real-time editing, and generates the complete 3D mesh from a single input image in only 0.7 seconds per object.
    • High-Quality Meshes: Achieves precise geometry and detailed textures, producing visually accurate and high-fidelity 3D assets.
    • Open Source and Free: Licensed under the Stability AI Community License, SPAR3D is free for both commercial and non-commercial use, making it accessible to a wide range of users.
    • Accessibility: The weights of SPAR3D are available on Hugging Face, and the code is available on GitHub, with access through the Stability AI Developer Platform API.
    • Compatibility: Ideal for running on NVIDIA RTX AI PCs

    How SPAR3D Works: A Two-Stage Architecture

    SPAR3D’s a Realtime 3D models, innovative approach involves a first-of-its-kind, two-stage architecture:

    1. Point Sampling Stage: A specialized point diffusion model generates a detailed point cloud, capturing the object’s fundamental structure. This point cloud represents the underlying structure of the object.
    2. Meshing Stage: The triplane transformer processes this point cloud alongside the original image features, producing high-resolution triplane data. This data is then used to generate the final 3D mesh, with precise geometry, texture, and illumination information.

    By combining precise point cloud sampling and advanced mesh generation, SPAR3D takes the best of both regression-based modeling’s precision and generative techniques’ flexibility. This results in accurate 360-degree predictions and highly controllable 3D object generation.

    Real-World Applications of SPAR3D a Realtime 3D model

    SPAR3D’s capabilities make it suitable for a wide variety of applications, including:

    • Game Development: Rapidly create and modify 3D game assets, from characters to environments.
    • Product Design: Quickly prototype and refine product designs, enabling faster iteration and improved design processes.
    • Architecture and Interior Design: Design and visualize 3D spaces and objects, creating immersive experiences for clients.
    • Filmmaking: Create realistic 3D props and environments for film and animation projects.
    • Augmented Reality (AR): Develop interactive 3D objects for AR applications with real-time manipulation.
    • Virtual Reality (VR): Generate high-quality 3D assets for VR environments.
    • Education: Provide interactive 3D models for education and training purposes.
    • Research: Enable faster iteration for generating high quality 3D assets in AI/ML research.

    Getting Started with SPAR3D, Realtime 3D model

    SPAR3D is designed for ease of access and implementation. You can get started by:

    • Downloading weights from Hugging Face: Access the pre-trained model weights to quickly integrate SPAR3D into your projects.
    • Accessing code on GitHub: Explore the open-source codebase, enabling you to modify and extend the model to meet specific needs.
    • Using Stability AI Developer Platform API: Integrate SPAR3D into your applications and workflows through the Stability AI Developer Platform API.

    SPAR3D by Stability AI is setting a new benchmark for real-time 3D object generation and editing. As a free and open-source tool, it empowers creators across multiple industries, from game development and product design to filmmaking and augmented reality. Its innovative architecture, unprecedented control, and lightning-fast generation make it an essential asset for anyone working with 3D content. Embrace the future of 3D modeling with SPAR3D and unlock new possibilities for creativity and efficiency.

  • LLM for Vehicles: Small Language Models for Vehicles for In-Car

    LLMs for vehicles, The automotive industry is undergoing a significant transformation, with software playing an increasingly vital role. Large language models (LLMs), specifically optimized small language models (sLMS), are emerging as powerful tools to enhance in-vehicle experiences. This post will delve into the world of LLMs for vehicles, explaining what they are, how we can benefit from them, their real-world use cases, and how they are optimized for in-vehicle function-calling. We will also briefly touch upon specific efforts like the Mercedes Benz LLM model.

    What are LLMs and sLMS?

    LLMs (Large Language Models) are sophisticated AI models trained on vast amounts of text data. They excel at understanding and generating human-like text, enabling a wide range of applications such as natural language processing, text generation, and question answering. However, traditional LLMs are often too large to be deployed on resource-constrained devices such as those found in vehicles.

    This is where sLMS (Small Language Models) come into play. sLMS, or Small large language models, are smaller, more efficient versions of LLMs, specifically designed to run on edge devices with limited computational resources. They are optimized for size and speed while maintaining a high level of performance, making them ideal for in-vehicle applications.

    How Can We Benefit from LLMs and sLMS in Vehicles?

    The integration of LLMs for vehicles, particularly through sLMS, offers numerous benefits:

    • Enhanced User Experience: Natural, intuitive voice commands make interacting with vehicle systems easier and more user-friendly.
    • Personalization: sLMS can understand user preferences and adapt vehicle settings accordingly.
    • Seamless Integration: New features and updates can be integrated more quickly, reducing development time.
    • Dynamic Control: Vehicle settings, such as seat heating, lighting, and temperature, can be controlled dynamically based on driver conditions.
    • Reduced Distractions: Voice-activated controls minimize the need for manual adjustments, enhancing driving safety.
    • Improved Safety: By having natural language processing of the data and the environment, the vehicle can get more accurate information and control, which ultimately makes the drive safer.

    Real Use Cases of LLMs and sLMS in Vehicles

    The real-world applications of LLMs for vehicles and sLMS are rapidly expanding, transforming in-car experiences:

    • Voice Assistants: Responding to voice commands for setting navigation, making calls, or playing music.
    • Interior Control: Dynamically adjusting vehicle settings such as seat heating, ambient lighting, and temperature based on user preferences.
    • Real-Time Information: Providing real-time updates on traffic, weather, and nearby points of interest.
    • Personalized Recommendations: Suggesting music, points of interest, or routes based on past preferences and driving habits.
    • On-Demand Information Access: Answering user questions about vehicle functions or maintenance.
    • Integration with External Services: Connecting with external applications for seamless control of smart home devices or scheduling apps.
    • Adaptive Driver Assistance Systems: Enhancing driver assist systems with better awareness of the environment and the driver.

    Optimizing Small Language Models for In-Vehicle Function-Calling

    Deploying sLMS effectively in vehicles requires careful optimization. The provided PDF highlights several techniques used to optimize the performance of Small Language Models for In-Vehicle Function-Calling:

    • Model Pruning: Reduces model size by removing less important connections or layers. Depth-wise pruning and width-wise pruning are employed.
      • Depth-wise pruning focuses on removing entire layers based on similarity.
      • Width-wise pruning aims at reducing the dimensionality of the layer through techniques like Principal Component Analysis (PCA).
    • Healing: Fine-tuning the pruned model to recover its performance, using techniques like Low-Rank Adaptation (LoRA) and full fine-tuning.
    • Quantization: Reducing the numerical precision of model weights to further decrease the size and computational requirements.
    • Task-Specific Fine-Tuning: Training models on custom datasets for in-vehicle function-calling, incorporating specialized tokens that map language model outputs to gRPC-based vehicle functions.

    Specifically, the optimization involves:

    • Utilizing special MB tokens for vehicle functions to ensure that the language model can directly control the vehicles functions.
    • Employing a multi-step prompt design to generate high-quality training examples.
    • Leveraging lightweight runtimes like llama.cpp for on-device inference.

    This combination of techniques enables efficient LLM for vehicles deployment on resource-constrained automotive hardware.

    Mercedes-Benz LLM Model

    Mercedes-Benz, like many automotive manufacturers, is actively exploring the use of LLMs for vehicles to enhance their in-car experiences. While the specific details of their current model are not the focus of the provided PDF, the research presented is closely aligned with those goals. The use of optimized sLMS such as Phi-3 mini, along with specific in-vehicle function-calling dataset is designed to align with the automotive sector and shows an effort to improve the in-car LLM technology.

    The approach used demonstrates how real-time, on-device inference of LLM for functions like voice-command, ambient adjustments or maintenance requests, is made possible through advanced optimization techniques and will allow for more advanced in vehicle experience.

    Read More on this from the paper published by Mercedes-Benz Research & Development Team.

  • Sonus-1: FREE Reasoning Model beats OpenAI’s new O1 Pro

    Introducing Sonus-1: A High-Performing, FREE Reasoning Model, Rubik’s Sonus 1 model is a free new model that can do reasoning across multiple tasks and beats OpenAI’s new O1 Pro mode for free.

    The Sonus-1 family of Large Language Models (LLMs) is designed to be both powerful and versatile, excelling across a range of applications. Sonus-1 is offered to the community completely free, allowing users to leverage cutting-edge AI without cost or restrictions.

    The Sonus-1 Family: Pro, Air, and Mini

    The Sonus-1 series is designed to cater to a variety of needs:

    • Sonus-1 Mini: Prioritizes speed, offering cost-effective solutions with fast performance.
    • Sonus-1 Air: Provides a versatile balance between performance and resource usage.
    • Sonus-1 Pro: Is optimized for complex tasks that demand the highest performance levels.
    • Sonus-1 Pro (w/ Reasoning): Is the flagship model, enhanced with chain-of-thought reasoning to tackle intricate problems.

    Sonus-1 Pro (w/ Reasoning): A Focus on High-Performance Reasoning

    The Sonus-1 Pro (w/ Reasoning) model is engineered to excel in challenging tasks requiring sophisticated problem-solving, particularly in reasoning, mathematics, and code.

    Benchmark Performance: Sonus-1 Pro Outperforms The Competition

    The Sonus-1 family, particularly the Pro model, demonstrates impressive performance across diverse benchmarks. Here’s a detailed breakdown, emphasizing the capabilities of the Sonus-1 Pro (w/ Reasoning) model:

    Sonus-1 capabilities

    Key Highlights from the Benchmark Data:

    • MMLU: The Sonus-1 Pro (w/ Reasoning) model achieves 90.15% demonstrating its powerful general reasoning capabilities.
    • MMLU-Pro: Achieves 73.1%, highlighting its robust capabilities for more complex reasoning problems.
    • Math (MATH-500): With a score of 91.8%, Sonus-1 Pro (w/ Reasoning) proves its prowess in handling intricate mathematical problems.
    • Reasoning (DROP): Achieves 88.9%, demonstrating its strong capabilities in reasoning tasks.
    • Reasoning (GPQA-Diamond): Achieves 67.3% on the challenging GPQA-Diamond, highlighting its ability in scientific reasoning.
    • Code (HumanEval): Scores 91.0%, showcasing its strong coding abilities.
    • Code (LiveCodeBench): Achieves 51.9%, displaying impressive performance in real-world code environments.
    • Math (GSM-8k): Achieves an impressive 97% on the challenging GSM-8k math test.
    • Code (Aider-Edit): Demonstrates solid performance in code editing by achieving 72.6%.

    Sonus-1 Pro excels in various benchmarks, and stands out in reasoning and mathematical tasks, often surpassing the performance of other proprietary models.

    Where to Try Sonus-1?

    The Sonus-1 suite of models can be explored at chat.sonus.ai. Users are encouraged to test the models and experience their performance firsthand.

    What’s Next?

    The development of high-performance, reliable, and privacy-focused LLMs is ongoing, with future releases planned to tackle even more complex problems.

    Try Sonus-1 Demo Here: https://chat.sonus.ai/sonus

  • NVIDIA NV Ingest for Complex Unstructured PDFs, Enterprise Documents

    What is NVIDIA NV Ingest?

    NVIDIA NV Ingest is not a static pipeline; it’s a dynamic microservice designed for processing various document formats, including PDF, DOCX, and PPTX. It uses NVIDIA NIM microservices to identify, extract, and contextualize information, such as text, tables, charts, and images. The core aim is to transform unstructured data into structured metadata and text, facilitating its use in downstream applications

    At its core, NVIDIA NV Ingest is a performance-oriented, scalable microservice designed for document content and metadata extraction. Leveraging specialized NVIDIA NIM microservices, this tool goes beyond simple text extraction. It intelligently identifies, contextualizes, and extracts text, tables, charts, and images from a variety of document formats, including PDFs, Word, and PowerPoint files. This enables a streamlined workflow for feeding data into downstream generative AI applications, such as retrieval-augmented generation (RAG) systems.

    NVIDIA Ingest works by accepting a JSON job description, outlining the document payload and the desired ingestion tasks. The result is a JSON dictionary containing a wealth of metadata about the extracted objects and associated processing details. It’s crucial to note that NVIDIA Ingest doesn’t simply act as a wrapper around existing parsing libraries; rather, it’s a flexible and adaptable system that is designed to manage complex document processing workflows.

    Key Capabilities

    Here’s what NVIDIA NV Ingest is capable of:

    • Multi-Format Support: Handles a variety of documents, including PDF, DOCX, PPTX, and image formats.
    • Versatile Extraction Methods: Offers multiple extraction methods per document type, balancing throughput and accuracy. For PDFs, you can leverage options like pdfium, Unstructured.io, and Adobe Content Extraction Services.
    • Advanced Pre- and Post-Processing: Supports text splitting, chunking, filtering, embedding generation, and image offloading.
    • Parallel Processing: Enables parallel document splitting, content classification (tables, charts, images, text), extraction, and contextualization via Optical Character Recognition (OCR).
    • Vector Database Integration: NVIDIA Ingest also manages the computation of embeddings and can optionally store these into vector database like Milvus

    Why NVIDIA NV Ingest?

    Unlike static pipelines, NVIDIA Ingest provides a flexible framework. It is not a wrapper for any specific parsing library. Instead, it orchestrates the document processing workflow based on your job description.

    The need to parse hundreds of thousands of complex, messy unstructured PDFs is often a major hurdle. NVIDIA Ingest is designed for exactly this scenario, providing a robust and scalable system for large-scale data processing. It breaks down complex PDFs into discrete content, contextualizes it through OCR, and outputs a structured JSON schema which is very easy to use for AI applications.

    Getting Started with NVIDIA NV Ingest

    To get started, you’ll need:

    • Hardware: NVIDIA GPUs (H100 or A100 with at least 80GB of memory, with minimum of 2 GPUs)

    Software

    • Operating System: Linux (Ubuntu 22.04 or later is recommended)
    • Docker: For containerizing and managing microservices
    • Docker Compose: For multi-container application deployment
    • CUDA Toolkit: (NVIDIA Driver >= 535, CUDA >= 12.2)
    • NVIDIA Container Toolkit: For running NVIDIA GPU-accelerated containers
    • NVIDIA API Key: Required for accessing pre-built containers from NVIDIA NGC. To get early access for NVIDIA Ingest https://developer.nvidia.com/nemo-microservices-early-access/join

    Step-by-Step Setup and Usage

    1. Starting NVIDIA NIM Microservices Containers

    1. Clone the repository:
      git clone
      https://github.com/nvidia/nv-ingest
      cd nv-ingest
    2. Log in to NVIDIA GPU Cloud (NGC):
      docker login nvcr.io
      # Username: $oauthtoken
      # Password: <Your API Key>
    3. Create a .env file: 
      Add your NGC API key and any other required paths:
      NGC_API_KEY=your_api_key NVIDIA_BUILD_API_KEY=optional_build_api_key
    4. Start the containers:
      sudo nvidia-ctk runtime configure --runtime=docker --set-as-default
      docker compose up

    Note: NIM containers might take 10-15 minutes to fully load models on first startup.

    2. Installing Python Client Dependencies

    1. Create a Python environment (optional but recommended):
      conda create --name nv-ingest-dev --file ./conda/environments/nv_ingest_environment.yml
      conda activate nv-ingest-dev
    2. Install the client:
      cd client
      pip install .

    if you are not using conda you can install directly

    #pip install -r requirements.txt
    #pip install .
    “`
    Note: You can perform these steps from your host machine or within the nv-ingest container.

    3. Submitting Ingestion Jobs

    Python Client Example:

    import logging, time
    
    from nv_ingest_client.client import NvIngestClient
    from nv_ingest_client.primitives import JobSpec
    from nv_ingest_client.primitives.tasks import ExtractTask
    from nv_ingest_client.util.file_processing.extract import extract_file_content
    
    logger = logging.getLogger("nv_ingest_client")
    
    file_name = "data/multimodal_test.pdf"
    file_content, file_type = extract_file_content(file_name)
    
    job_spec = JobSpec(
     document_type=file_type,
     payload=file_content,
     source_id=file_name,
     source_name=file_name,
     extended_options={
         "tracing_options": {
             "trace": True,
             "ts_send": time.time_ns()
         }
     }
    )
    
    extract_task = ExtractTask(
     document_type=file_type,
     extract_text=True,
     extract_images=True,
     extract_tables=True
    )
    
    job_spec.add_task(extract_task)
    
    client = NvIngestClient(
     message_client_hostname="localhost",  # Host where nv-ingest-ms-runtime is running
     message_client_port=7670  # REST port, defaults to 7670
    )
    
    job_id = client.add_job(job_spec)
    client.submit_job(job_id, "morpheus_task_queue")
    result = client.fetch_job_result(job_id, timeout=60)
    print(f"Got {len(result)} results")

    Command Line (nv-ingest-cli) Example:

    nv-ingest-cli \
        --doc ./data/multimodal_test.pdf \
        --output_directory ./processed_docs \
        --task='extract:{"document_type": "pdf", "extract_method": "pdfium", "extract_tables": "true", "extract_images": "true"}' \
        --client_host=localhost \
        --client_port=7670

    Note: Make sure to adjust the file_path, client_host and client_port as per your setup.

    Note: extract_tables controls both table and chart extraction, you can disable chart extraction using extract_charts parameter set to false.

    4. Inspecting Results

    Post ingestion, results can be found in processed_docs directory, under text, image and structured subdirectories. Each result will contain corresponding json metadata files. You can inspect the extracted images using the provided image viewer script:

    1. First, install tkinter by running the following commands depending on your OS.

      For Ubuntu/Debian:
      sudo apt-get update
      sudo apt-get install python3-tk

      # For Fedora/RHEL:
      sudo dnf install python3-tkinter

      # For MacOS
      brew install python-tk
    2. Run image viewer:
      python src/util/image_viewer.py --file_path ./processed_docs/image/multimodal_test.pdf.metadata.json

    Understanding the Output

    The output of NVIDIA NV Ingest is a structured JSON document, which contains:

    • Extracted Text: Text content from the document.
    • Extracted Tables: Table data in structured format.
    • Extracted Charts: Information about charts present in the document.
    • Extracted Images: Metadata for extracted images.
    • Processing Annotations: Timing and tracing data for analysis.

    This output can be easily integrated into various systems, including vector databases for semantic search and LLM applications.

    This output can be easily integrated into various systems, including vector databases for semantic search and LLM applications.

    NVIDIA NV Ingest Use Cases

    NVIDIA NV Ingest is ideal for various applications, including:

    • Retrieval-Augmented Generation (RAG): Enhance LLMs with accurate and contextualized data from your documents.
    • Enterprise Search: Improve search capabilities by indexing text and metadata from large document repositories.
    • Data Analysis: Unlock hidden patterns and insights within unstructured data.
    • Automated Document Processing: Streamline workflows by automating the extraction process from unstructured documents.

    Troubleshooting

    Common Issues

    • NIM Containers Not Starting: Check resource availability (GPU memory, CPU), verify NGC login details, and ensure the correct CUDA driver is installed.
    • Python Client Errors: Verify dependencies are installed correctly and the client is configured to connect with the running service.
    • Job Failures: Examine the logs for detailed error messages, check the input document for errors, and verify task configuration.

    Tips

    • Verbose Logging: Enable verbose logging by setting NIM_TRITON_LOG_VERBOSE=1 in docker-compose.yaml to help diagnose issues.
    • Container Logs: Use docker logs to inspect logs for each container to identify problems.
    • GPU Utilization: Use nvidia-smi to monitor GPU activity. If it takes more than a minute for nvidia-smi command to return there is a high chance that the GPU is busy setting up the models.