### Prepare AIME 2025 Dataset for DeepThinkLLM Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Prepares the AIME 2025 dataset into JSONL format suitable for use with DeepThinkLLM scripts. This involves loading the dataset from Hugging Face and converting each example into a JSON object with 'question' and 'answer' keys. The output is saved to 'aime_2025.jsonl'. ```python import json from datasets import load_dataset # Load dataset dataset = load_dataset("MathArena/aime_2025", split="train") # Convert to JSONL with open("aime_2025.jsonl", "w", encoding="utf-8") as f: for example in dataset: entry = { "question": example["problem"], "answer": str(example["answer"]) } f.write(json.dumps(entry, ensure_ascii=False) + "\n") print(f"Converted {len(dataset)} examples to aime_2025.jsonl") ``` -------------------------------- ### Install DeepConf Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Installs the DeepConf package and its requirements. Ensure you have Python 3.9+ and pip or uv installed. ```bash pip install deepconf uv pip install -r requirements.txt ``` -------------------------------- ### Run DeepThinkLLM Online Accelerated Mode Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Executes DeepThinkLLM in accelerated online mode with confidence-aware early-exit. This script uses specific command-line arguments for configuration. The voting algorithms are applied after the online filtering step. ```bash python examples/example_online.py --qid $1 --rid $2 --dataset brumo_2025.jsonl --total_budget 256 --output_dir online-dpsk ``` -------------------------------- ### Install DeepThinkLLM Python Package Dependencies Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Installs necessary Python packages for DeepThinkLLM, including pandas, numpy, and tqdm. These libraries are used for data manipulation, numerical operations, and progress bar visualization, respectively. This command is executed via pip. ```bash pip install pandas numpy tqdm ``` -------------------------------- ### Run DeepThinkLLM Baseline Mode (No Early-Exit) Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Executes DeepThinkLLM in baseline mode without early-exit for fair comparison. This script utilizes similar command-line arguments as the online mode but disables the early-exit feature. It serves as a benchmark against the accelerated online mode. ```bash python examples/example_online_baseline.py --qid $1 --rid $2 --dataset brumo_2025.jsonl --total_budget 256 --output_dir baseline-dpsk ``` -------------------------------- ### Analyze DeepThinkLLM Online Runs Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Analyzes the logs and results from accelerated online runs of DeepThinkLLM. This script aggregates metrics such as accuracy, token usage, and generation time across multiple runs. It requires the output directory from the online execution. ```bash python examples/example_analyze_online.py --output_dir ./online-dpsk/ --max_qid 29 --rids 1 ``` -------------------------------- ### Analyze DeepThinkLLM Baseline Runs Source: https://github.com/facebookresearch/deepconf/blob/main/examples/README.md Analyzes the logs and results from baseline (no early-exit) runs of DeepThinkLLM. Similar to the online analyzer, this script aggregates key performance metrics. It requires the output directory generated by the baseline execution script. ```bash python examples/example_analyze_online_baseline.py --output_dir ./baseline-dpsk/ --max_qid 29 --rids 1 ``` -------------------------------- ### Basic DeepConf Usage (Python) Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Demonstrates initializing DeepThinkLLM, preparing a prompt with chat templates, and running the 'deepthink' method in offline mode with multiple voting enabled. Results are then iterated and printed. ```python from deepconf import DeepThinkLLM # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompt question = "What is the square root of 144?" messages = [ {"role": "user", "content": question} ] prompt = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Run offline mode with multiple voting result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=64, compute_multiple_voting=True ) # Evaluate results for method, method_result in result.voting_results.items(): if method_result and method_result.get('answer'): print(f"{method}: {method_result['answer']}") ``` -------------------------------- ### Initialize DeepThinkLLM Wrapper Source: https://context7.com/facebookresearch/deepconf/llms.txt Initializes the DeepThinkLLM wrapper around vLLM, enabling deep thinking capabilities. Supports basic model loading and advanced configuration with custom vLLM parameters. Provides access to the underlying vLLM tokenizer for prompt preparation. ```python from deepconf import DeepThinkLLM # Basic initialization deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Advanced initialization with custom vLLM parameters deep_llm = DeepThinkLLM( model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B", tensor_parallel_size=4, enable_prefix_caching=True, trust_remote_code=True ) # The wrapper provides access to the underlying vLLM tokenizer tokenizer = deep_llm.tokenizer ``` -------------------------------- ### Result Serialization and Analysis with Pickle and JSON Source: https://context7.com/facebookresearch/deepconf/llms.txt Demonstrates how to serialize DeepThinkLLM results using pickle for Python analysis and how to access comprehensive statistics like token counts, timing, and configuration. It also shows how to pretty-print detailed voting results. ```python from deepconf import DeepThinkLLM import pickle import json # Run deep thinking result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=128, compute_multiple_voting=True ) # Convert to dictionary for serialization result_dict = result.to_dict() # Save as pickle for Python analysis with open('result.pkl', 'wb') as f: pickle.dump(result_dict, f) # Access comprehensive metrics print(f"Token statistics:") print(f" Total tokens: {result.total_tokens}") print(f" Avg tokens/trace: {result.avg_tokens_per_trace:.1f}") print(f"\nTiming statistics:") print(f" Generation time: {result.generation_time:.2f}s") print(f" Processing time: {result.processing_time:.2f}s") print(f" Total time: {result.total_time:.2f}s") print(f" Throughput: {result.overall_throughput:.1f} tokens/sec") print(f"\nConfiguration used:") for key, value in result.config.items(): print(f" {key}: {value}") # Pretty print voting results result.print_detailed_voting_results() ``` -------------------------------- ### DeepThinkLLM Initialization Source: https://context7.com/facebookresearch/deepconf/llms.txt Initialize the deep thinking wrapper around vLLM with model configuration and parallel processing settings. You can perform basic initialization or advanced initialization with custom vLLM parameters. ```APIDOC ## DeepThinkLLM Initialization ### Description Initialize the deep thinking wrapper around vLLM with model configuration and parallel processing settings. ### Method Constructor ### Endpoint N/A (Class Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from deepconf import DeepThinkLLM # Basic initialization deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Advanced initialization with custom vLLM parameters deep_llm = DeepThinkLLM( model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B", tensor_parallel_size=4, enable_prefix_caching=True, trust_remote_code=True ) # The wrapper provides access to the underlying vLLM tokenizer tokenizer = deep_llm.tokenizer ``` ### Response #### Success Response (200) N/A (Initialization) #### Response Example N/A ``` -------------------------------- ### Offline Inference and Evaluation with DeepThinkLLM Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Loads question data, initializes DeepThinkLLM, prepares a prompt using a chat template, runs inference in offline mode with a specified budget, and evaluates the results by comparing the predicted answer to the ground truth. ```python # Load question data question = "What is 2^10?" ground_truth = "1024" # Initialize and prepare deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") messages = [ {"role": "user", "content": question} ] prompt = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Run inference result = deep_llm.deepthink(prompt=prompt, mode="offline", budget=32) # Evaluate results for method, method_result in result.voting_results.items(): if method_result: is_correct = int(method_result['answer']) == int(ground_truth) print(f"{method}: {is_correct}") ``` -------------------------------- ### Confidence Computation and Analysis from Traces Source: https://context7.com/facebookresearch/deepconf/llms.txt Illustrates the computation of various confidence metrics (mean, tail, bottom window) from individual reasoning traces after running deepthink. This helps in analyzing the quality and reliability of the generated reasoning. ```python from deepconf.utils import ( compute_confidence, compute_least_grouped, calculate_mean_confidence, calculate_tail_confidence, calculate_bottom_window_confidence ) # After running deepthink in offline mode result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=64, compute_multiple_voting=True ) # Analyze individual traces for i, trace in enumerate(result.all_traces[:5]): mean_conf = calculate_mean_confidence(trace) tail_conf = calculate_tail_confidence(trace, tail_tokens=2048) bottom_conf = calculate_bottom_window_confidence( trace, window_size=2048, bottom_percent=0.1 ) print(f"Trace {i}:") print(f" Answer: {trace.get('extracted_answer', 'None')}") print(f" Mean confidence: {mean_conf:.3f}") print(f" Tail confidence: {tail_conf:.3f}") print(f" Bottom 10% window confidence: {bottom_conf:.3f}") print(f" Tokens: {trace['num_tokens']}") ``` -------------------------------- ### Standard vLLM Text Generation with DeepThinkLLM Source: https://context7.com/facebookresearch/deepconf/llms.txt Initializes DeepThinkLLM for standard text generation using vLLM. It takes a list of prompts and SamplingParams for generation, then processes and prints the outputs. This method is suitable for straightforward text completion tasks. ```python from deepconf import DeepThinkLLM from vllm import SamplingParams # Initialize deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompts prompts = ["Explain quantum computing", "What is machine learning?"] # Standard generation parameters sampling_params = SamplingParams( temperature=0.7, top_p=0.9, max_tokens=512 ) # Generate using vLLM directly outputs = deep_llm.generate(prompts, sampling_params) # Process outputs for output in outputs: print(f"Prompt: {output.prompt}") print(f"Generated: {output.outputs[0].text}") ``` -------------------------------- ### Online Inference with Confidence Analysis using DeepThinkLLM Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Performs online inference using DeepThinkLLM with confidence analysis. It sets up parameters like warmup traces and total budget, then prints the confidence threshold, and the number of warmup and final traces. Finally, it analyzes traces above the confidence threshold. ```python # Online mode with confidence analysis result = deep_llm.deepthink( prompt=prompt, mode="online", warmup_traces=16, total_budget=64 ) print(f"Confidence threshold: {result.conf_bar:.3f}") print(f"Warmup traces: {len(result.warmup_traces)}") print(f"Final traces: {len(result.final_traces)}") # Analyze traces by confidence above_threshold = [t for t in result.warmup_traces if t['min_conf'] >= result.conf_bar] print(f"Traces above threshold: {len(above_threshold)}") ``` -------------------------------- ### Online Mode Deep Thinking with Early Stopping Source: https://context7.com/facebookresearch/deepconf/llms.txt Employs an online mode for dynamic trace generation with confidence-based early stopping. Features a warmup phase for calibration and dynamically adjusts computation based on a confidence percentile threshold. Provides analysis of confidence levels, trace counts, and early stopping reasons. ```python from deepconf import DeepThinkLLM from vllm import SamplingParams # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompt question = "Solve: If x^2 + 5x + 6 = 0, what are the values of x?" messages = [{"role": "user", "content": question}] prompt = deep_llm.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Configure sampling sampling_params = SamplingParams( temperature=0.6, top_p=0.95, max_tokens=64000, logprobs=20 ) # Run online mode with confidence-based early stopping result = deep_llm.deepthink( prompt=prompt, mode="online", warmup_traces=16, # Calibration phase traces total_budget=256, # Maximum traces to generate confidence_percentile=90, # Threshold at 90th percentile window_size=2048, # Sliding window for confidence compute_multiple_voting=True, sampling_params=sampling_params ) # Analyze confidence-based results print(f"Confidence threshold: {result.conf_bar:.3f}") print(f"Warmup traces: {len(result.warmup_traces)}") print(f"Final traces: {len(result.final_traces)}") print(f"Final answer: {result.final_answer}") # Check which traces passed confidence threshold above_threshold = [ trace for trace in result.warmup_traces if trace['min_conf'] >= result.conf_bar ] print(f"Traces above threshold: {len(above_threshold)}") # Check early stopped traces early_stopped = [ trace for trace in result.final_traces if trace.get('stop_reason') == 'gconf_threshold' ] print(f"Early stopped traces: {len(early_stopped)}") ``` -------------------------------- ### Online Mode with Confidence-Based Early Stopping Source: https://context7.com/facebookresearch/deepconf/llms.txt Generate traces dynamically with a warmup phase and confidence threshold for early stopping optimization. This mode is designed to dynamically adjust computation based on real-time confidence metrics. ```APIDOC ## Online Mode with Confidence-Based Early Stopping ### Description Generate traces dynamically with warmup phase and confidence threshold for early stopping optimization. ### Method `deepthink` ### Endpoint N/A (Method Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from deepconf import DeepThinkLLM from vllm import SamplingParams # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompt question = "Solve: If x^2 + 5x + 6 = 0, what are the values of x?" messages = [{"role": "user", "content": question}] prompt = deep_llm.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Configure sampling sampling_params = SamplingParams( temperature=0.6, top_p=0.95, max_tokens=64000, logprobs=20 ) # Run online mode with confidence-based early stopping result = deep_llm.deepthink( prompt=prompt, mode="online", warmup_traces=16, # Calibration phase traces total_budget=256, # Maximum traces to generate confidence_percentile=90, # Threshold at 90th percentile window_size=2048, # Sliding window for confidence compute_multiple_voting=True, sampling_params=sampling_params ) # Analyze confidence-based results print(f"Confidence threshold: {result.conf_bar:.3f}") print(f"Warmup traces: {len(result.warmup_traces)}") print(f"Final traces: {len(result.final_traces)}") print(f"Final answer: {result.final_answer}") # Check which traces passed confidence threshold above_threshold = [ trace for trace in result.warmup_traces if trace['min_conf'] >= result.conf_bar ] print(f"Traces above threshold: {len(above_threshold)}") # Check early stopped traces early_stopped = [ trace for trace in result.final_traces if trace.get('stop_reason') == 'gconf_threshold' ] print(f"Early stopped traces: {len(early_stopped)}") ``` ### Response #### Success Response (200) - **conf_bar** (float) - The calculated confidence threshold for early stopping. - **warmup_traces** (list) - A list of traces generated during the warmup phase. - Each trace is a dictionary containing details like 'min_conf' (minimum confidence in the trace). - **final_traces** (list) - A list of traces generated until early stopping or total budget is reached. - Each trace is a dictionary which may contain 'stop_reason' if early stopping occurred. - **final_answer** (string) - The aggregated final answer. - **voting_results** (dict) - A dictionary containing results from different voting methods (if `compute_multiple_voting` is True). #### Response Example ```json { "conf_bar": 0.925, "warmup_traces": [ { "trace_id": 0, "answer": "x=-2", "min_conf": 0.91 }, { "trace_id": 1, "answer": "x=-3", "min_conf": 0.95 } ], "final_traces": [ { "trace_id": 2, "answer": "x=-2", "min_conf": 0.96, "stop_reason": "gconf_threshold" }, { "trace_id": 3, "answer": "x=-3", "min_conf": 0.94 } ], "final_answer": "x=-2, x=-3", "voting_results": { "majority_voting": { "answer": "x=-2, x=-3", "confidence": 0.95, "num_votes": 2 } } } ``` ``` -------------------------------- ### DeepConf deepthink() Online Mode (Python) Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Executes the deepthink() method in 'online' mode, utilizing confidence-based early stopping. Requires specifying warmup_traces for calibration and total_budget for the maximum number of traces. ```python result = deep_llm.deepthink( prompt=prompt, mode="online", warmup_traces=16, total_budget=256, sampling_params=sampling_params ) ``` -------------------------------- ### Applying Multiple Voting Strategies for Answer Aggregation Source: https://context7.com/facebookresearch/deepconf/llms.txt Demonstrates how to compute and compare various voting strategies for answer aggregation after running deepthink in offline mode. It iterates through available methods, printing the aggregated answer and its associated votes and confidence. ```python from deepconf import DeepThinkLLM from deepconf.utils import compute_all_voting_results # After running deepthink result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=128, compute_multiple_voting=True ) # Available voting methods: # - majority: Simple majority voting # - mean_confidence_weighted: Weighted by average confidence # - tail_confidence_weighted: Weighted by last 2048 tokens confidence # - bottom_window_weighted: Weighted by lowest sliding window confidence # - min_window_weighted: Weighted by minimum window confidence # - top10_tail_filtered: Top 10% by tail confidence, then weighted vote # - top10_bottom_window_filtered: Top 10% by bottom window, then weighted vote # Compare different voting methods for method in result.get_voting_method_names(): method_data = result.voting_results[method] if method_data: print(f"{method}:") print(f" Answer: {method_data['answer']}") print(f" Votes: {method_data['num_votes']}") if method_data.get('confidence'): print(f" Confidence: {method_data['confidence']:.3f}") ``` -------------------------------- ### Batch Processing and Evaluation with DeepThinkLLM Source: https://context7.com/facebookresearch/deepconf/llms.txt This Python script processes a list of questions from a JSONL file, runs them through the DeepThinkLLM in offline mode, evaluates the generated answers against ground truth using math_equal, and prints summary statistics. It requires the 'deepconf' and 'dynasor' libraries. ```python import json from deepconf import DeepThinkLLM from dynasor.core.evaluator import math_equal # Load dataset with open('questions.jsonl', 'r') as f: questions = [json.loads(line) for line in f] # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") results = [] for q_data in questions[:10]: question = q_data['question'] ground_truth = q_data['answer'] # Prepare prompt messages = [{"role": "user", "content": question}] prompt = deep_llm.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Run deep thinking result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=64, compute_multiple_voting=True ) # Evaluate each voting method evaluation = {} for method, method_result in result.voting_results.items(): if method_result and method_result.get('answer'): is_correct = math_equal(method_result['answer'], ground_truth) evaluation[method] = { 'answer': method_result['answer'], 'correct': is_correct, 'confidence': method_result.get('confidence') } results.append({ 'question': question, 'ground_truth': ground_truth, 'evaluation': evaluation, 'tokens_used': result.total_tokens, 'time_taken': result.total_time }) # Print summary correct_methods = sum(1 for e in evaluation.values() if e['correct']) print(f"Q: {question[:50]}... | " f"Correct methods: {correct_methods}/{len(evaluation)} | " f"Tokens: {result.total_tokens}") # Calculate aggregate statistics total_correct = sum( sum(1 for e in r['evaluation'].values() if e['correct']) for r in results ) total_methods = sum(len(r['evaluation']) for r in results) print(f"\nOverall method accuracy: {total_correct}/{total_methods} " f"({100*total_correct/total_methods:.1f}%)") ``` -------------------------------- ### deepthink() Method - Online Mode Source: https://github.com/facebookresearch/deepconf/blob/main/README.md The `deepthink()` method in online mode uses confidence-based early stopping with warmup traces for efficient reasoning. ```APIDOC ## `deepthink()` Function - Online Mode ### Description Enables confidence-based reasoning with early stopping. It establishes thresholds with warmup traces and applies early stopping. ### Method ```python deep_llm.deepthink(prompt: str, mode: str = "online", warmup_traces: int, total_budget: int, sampling_params: dict = None) ``` ### Parameters * **prompt** (str) - Required - The input prompt for reasoning. * **mode** (str) - Required - Must be set to `"online"`. * **warmup_traces** (int) - Required - Number of calibration runs for establishing thresholds. * **total_budget** (int) - Required - Maximum number of traces to generate. * **sampling_params** (dict) - Optional - Parameters for sampling strategies. ### Request Example ```python result = deep_llm.deepthink( prompt=prompt, mode="online", warmup_traces=16, total_budget=256, sampling_params=sampling_params ) ``` ### Response Returns a `DeepThinkOutput` dataclass containing results, voting information, traces, confidence thresholds, statistics, and configuration. ``` -------------------------------- ### Custom Answer Extraction using deepconf.utils Source: https://context7.com/facebookresearch/deepconf/llms.txt Shows how to use the `extract_answer` utility function to parse specific answer formats, particularly those enclosed in `\boxed{}`. It handles simple cases, nested braces, and returns None when no boxed answer is found. ```python from deepconf.utils import extract_answer # Extract boxed LaTeX answers text1 = "The solution is \boxed{42} which we derived from..." answer1 = extract_answer(text1) print(f"Extracted: {answer1}") # Output: "42" # Works with nested braces text2 = "Therefore \boxed{\frac{3}{4}} is the final answer" answer2 = extract_answer(text2) print(f"Extracted: {answer2}") # Output: "\frac{3}{4}" # Returns None if no boxed answer found text3 = "The answer is 42" answer3 = extract_answer(text3) print(f"Extracted: {answer3}") # Output: None ``` -------------------------------- ### Offline Mode Deep Thinking with Voting Source: https://context7.com/facebookresearch/deepconf/llms.txt Generates a fixed number of reasoning traces in offline mode and aggregates answers using various voting strategies. Requires vLLM's SamplingParams for generation configuration. Outputs include the final aggregated answer, trace counts, and detailed voting results per method. ```python from deepconf import DeepThinkLLM from vllm import SamplingParams # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompt with chat template question = "What is the square root of 144?" messages = [{"role": "user", "content": question}] prompt = deep_llm.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Configure sampling parameters sampling_params = SamplingParams( temperature=0.6, top_p=0.95, max_tokens=32000, logprobs=20 ) # Run offline deep thinking with 64 parallel traces result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=64, window_size=2048, compute_multiple_voting=True, sampling_params=sampling_params ) # Access results from different voting methods print(f"Final answer: {result.final_answer}") print(f"Total traces: {result.total_traces_count}") print(f"Total tokens: {result.total_tokens}") # Iterate through voting results for method, method_result in result.voting_results.items(): if method_result and method_result.get('answer'): print(f"{method}: {method_result['answer']} " f"(confidence: {method_result.get('confidence', 'N/A')}, " f"votes: {method_result.get('num_votes', 0)})") ``` -------------------------------- ### DeepConf deepthink() Offline Mode (Python) Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Demonstrates running the deepthink() method in 'offline' mode for batch generation. This mode allows specifying a budget for the number of traces and enables all voting methods by setting compute_multiple_voting to True. ```python result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=512, compute_multiple_voting=True, sampling_params=sampling_params ) ``` -------------------------------- ### DeepThinkOutput Format Source: https://github.com/facebookresearch/deepconf/blob/main/README.md Describes the structure of the `DeepThinkOutput` dataclass returned by the `deepthink()` method. ```APIDOC ## Output Format ### Description The output of `deepthink()` is returned as a `DeepThinkOutput` dataclass, which organizes results and metadata for easy analysis. ### Fields * **Primary Results** * `final_answer` (str) - The final selected answer. * `voted_answer` (str) - The answer from the default voting method. * **Voting Results** * `voting_results` (dict) - A dictionary containing answers and confidences from all voting strategies. * **Traces & Confidence** * `all_traces` (list) - All generated reasoning traces. * `warmup_traces` (list) - Reasoning traces from the warmup phase (online mode). * `final_traces` (list) - Reasoning traces from the final phase. * `conf_bar` (float) - Confidence threshold (online mode only). * **Statistics** * `total_traces_count` (int) - Total number of traces generated. * Token usage per stage. * Timing information (generation, processing, initialization). * **Config & Metadata** * `config` (dict) - The configuration used for the run. * `mode` (str) - The mode used (`"online"` or `"offline"`). * `timestamp` (str) - The timestamp of the run. ``` -------------------------------- ### Offline Mode Deep Thinking Source: https://context7.com/facebookresearch/deepconf/llms.txt Generate a fixed budget of reasoning traces and apply multiple voting strategies for answer aggregation. This mode is suitable for comprehensive analysis when a fixed computational budget is available. ```APIDOC ## Offline Mode Deep Thinking ### Description Generate a fixed budget of reasoning traces and apply multiple voting strategies for answer aggregation. ### Method `deepthink` ### Endpoint N/A (Method Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from deepconf import DeepThinkLLM from vllm import SamplingParams # Initialize model deep_llm = DeepThinkLLM(model="deepseek-ai/DeepSeek-R1-0528-Qwen3-8B") # Prepare prompt with chat template question = "What is the square root of 144?" messages = [{"role": "user", "content": question}] prompt = deep_llm.tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) # Configure sampling parameters sampling_params = SamplingParams( temperature=0.6, top_p=0.95, max_tokens=32000, logprobs=20 ) # Run offline deep thinking with 64 parallel traces result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=64, window_size=2048, compute_multiple_voting=True, sampling_params=sampling_params ) # Access results from different voting methods print(f"Final answer: {result.final_answer}") print(f"Total traces: {result.total_traces_count}") print(f"Total tokens: {result.total_tokens}") # Iterate through voting results for method, method_result in result.voting_results.items(): if method_result and method_result.get('answer'): print(f"{method}: {method_result['answer']} " f"(confidence: {method_result.get('confidence', 'N/A')}, " f"votes: {method_result.get('num_votes', 0)})") ``` ### Response #### Success Response (200) - **final_answer** (string) - The aggregated final answer based on voting strategies. - **total_traces_count** (integer) - The total number of reasoning traces generated. - **total_tokens** (integer) - The total number of tokens processed across all traces. - **voting_results** (dict) - A dictionary containing results from different voting methods. - **method_name** (dict) - Contains the aggregated answer, confidence score, and number of votes for a specific voting method. - **answer** (string) - The answer determined by this voting method. - **confidence** (float) - The confidence score for the answer. - **num_votes** (integer) - The number of votes received for this answer. #### Response Example ```json { "final_answer": "12.0", "total_traces_count": 64, "total_tokens": 5120, "voting_results": { "majority_voting": { "answer": "12.0", "confidence": 0.95, "num_votes": 50 }, "confidence_weighted_voting": { "answer": "12.0", "confidence": 0.98, "num_votes": 64 } } } ``` ``` -------------------------------- ### DeepThinkLLM Class Source: https://github.com/facebookresearch/deepconf/blob/main/README.md The DeepThinkLLM class is a wrapper around vLLM that adds deep thinking capabilities for enhanced reasoning. It supports standard text generation and specialized deep thinking methods. ```APIDOC ## DeepThinkLLM Class ### Description A lightweight wrapper around vLLM that extends standard generation with *deep thinking* capabilities. It supports two main methods: `generate()` for standard text generation and `deepthink()` for enhanced reasoning. ### Initialization ```python DeepThinkLLM(model: str, **vllm_kwargs) ``` ### Parameters * **model** (str) - Required - Model path or name (e.g., `deepseek-ai/DeepSeek-R1-0528-Qwen3-8B`). * **vllm_kwargs** - Optional - All standard vLLM initialization parameters are supported, such as `enable_prefix_caching=True`, `tensor_parallel_size=...`. This makes it fully compatible with vLLM while adding reasoning-specific extensions. ``` -------------------------------- ### deepthink() Method - Offline Mode Source: https://github.com/facebookresearch/deepconf/blob/main/README.md The `deepthink()` method in offline mode generates all traces at once and applies multiple voting strategies for batch reasoning. ```APIDOC ## `deepthink()` Function - Offline Mode ### Description Generates all traces at once and applies multiple voting strategies. Suitable for batch processing and comprehensive analysis. ### Method ```python deep_llm.deepthink(prompt: str, mode: str = "offline", budget: int, compute_multiple_voting: bool, sampling_params: dict = None) ``` ### Parameters * **prompt** (str) - Required - The input prompt for reasoning. * **mode** (str) - Required - Must be set to `"offline"`. * **budget** (int) - Required - The number of traces to generate. * **compute_multiple_voting** (bool) - Required - Enable all voting methods. * **sampling_params** (dict) - Optional - Parameters for sampling strategies. ### Request Example ```python result = deep_llm.deepthink( prompt=prompt, mode="offline", budget=512, compute_multiple_voting=True, sampling_params=sampling_params ) ``` ### Response Returns a `DeepThinkOutput` dataclass containing results, voting information, traces, confidence thresholds, statistics, and configuration. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.