初始化项目,由ModelHub XC社区提供模型
Model: nv-community/OpenMath-Nemotron-14B-Kaggle Source: Original Platform
This commit is contained in:
49
.gitattributes
vendored
Normal file
49
.gitattributes
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
*.db* filter=lfs diff=lfs merge=lfs -text
|
||||
*.ark* filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
||||
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.gguf* filter=lfs diff=lfs merge=lfs -text
|
||||
*.ggml filter=lfs diff=lfs merge=lfs -text
|
||||
*.llamafile* filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||
4
BIAS.md
Normal file
4
BIAS.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Field | Response
|
||||
:---------------------------------------------------------------------------------------------------|:---------------
|
||||
Participation considerations from adversely impacted groups [protected classes](https://www.senate.ca.gov/content/protected-classes) in model design and testing: | None
|
||||
Measures taken to mitigate against unwanted bias: | None
|
||||
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
FROM igitman/nemo-skills-vllm:0.6.0 as base
|
||||
|
||||
# Install NeMo-Skills and dependencies
|
||||
RUN git clone https://github.com/NVIDIA/NeMo-Skills \
|
||||
&& cd NeMo-Skills \
|
||||
&& pip install --ignore-installed blinker \
|
||||
&& pip install -e . \
|
||||
&& pip install -r requirements/code_execution.txt
|
||||
|
||||
# Ensure python is available
|
||||
RUN ln -s /usr/bin/python3 /usr/bin/python
|
||||
|
||||
# Copy our custom files
|
||||
COPY handler.py server.py /usr/local/endpoint/
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
||||
# Copy and set up entrypoint script
|
||||
COPY entrypoint.sh /usr/local/endpoint/
|
||||
RUN chmod +x /usr/local/endpoint/entrypoint.sh
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /usr/local/endpoint
|
||||
|
||||
ENTRYPOINT ["/usr/local/endpoint/entrypoint.sh"]
|
||||
13
EXPLAINABILITY.md
Normal file
13
EXPLAINABILITY.md
Normal file
@@ -0,0 +1,13 @@
|
||||
Field | Response
|
||||
:------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------
|
||||
Intended Domain: | Text generation, reasoning, solving mathematical problems.
|
||||
Model Type: | Text-to-text transformer
|
||||
Intended Users: | This model is intended for developers, researchers, and customers building/utilizing LLMs.
|
||||
Output: | Text String(s)
|
||||
Describe how the model works: | Generates text by predicting the next word or token based on the context provided in the input sequence using multiple self-attention layers.
|
||||
Name the adversely impacted groups this has been tested to deliver comparable outcomes regardless of: | Not Applicable
|
||||
Technical Limitations & Mitigation: | The model was optimized for solving mathematical problems and thus might not be able to provide adequate answers for non-mathematical queries. The model was trained on questions with verifiable final answers, and thus may not be able to prove theorems.
|
||||
Verified to have met prescribed NVIDIA quality standards: | Yes
|
||||
Performance Metrics: | Accuracy
|
||||
Potential Known Risks: | The model was optimized explicitly for solving mathematical problems and as such is more susceptible to prompt injection and jailbreaking in various forms as a result of its training. This means that the model should be paired with additional rails or system filtering to limit exposure to instructions from malicious sources -- either directly or indirectly by retrieval (e.g. via visiting a website) -- as they may yield outputs that can lead to harmful, system-level outcomes up to and including remote code execution in agentic systems when effective security controls including guardrails are not in place. The model was trained on data that contains toxic language and societal biases originally crawled from the internet. Therefore, the model may amplify those biases and return toxic responses especially when prompted with toxic prompts. The model may generate answers that may be inaccurate, omit key information, or include irrelevant or redundant text producing socially unacceptable or undesirable text, even if the prompt itself does not include anything explicitly offensive.
|
||||
Licensing: | Use of this model is governed by [CC-BY-4.0]((https://creativecommons.org/licenses/by/4.0/)) license. Additional Information: [Apache License Version 2.0](https://huggingface.co/Qwen/Qwen2.5-Math-1.5B/blob/main/LICENSE)
|
||||
9
PRIVACY.md
Normal file
9
PRIVACY.md
Normal file
@@ -0,0 +1,9 @@
|
||||
Field | Response
|
||||
:----------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------
|
||||
Generatable or reverse engineerable personal data? | None
|
||||
Personal data used to create this model? | None Known
|
||||
How often is dataset reviewed? | Before Release
|
||||
Is there provenance for all datasets used in training? | Yes
|
||||
Does data labeling (annotation, metadata) comply with privacy laws? | Yes
|
||||
Is data compliant with data subject requests for data correction or removal, if such a request was made? | No, not possible with externally-sourced data.
|
||||
Applicable Privacy Policy | https://www.nvidia.com/en-us/about-nvidia/privacy-policy/
|
||||
183
README.md
Normal file
183
README.md
Normal file
@@ -0,0 +1,183 @@
|
||||
---
|
||||
license: cc-by-4.0
|
||||
base_model:
|
||||
- Qwen/Qwen2.5-14B
|
||||
datasets:
|
||||
- nvidia/OpenMathReasoning
|
||||
language:
|
||||
- en
|
||||
tags:
|
||||
- nvidia
|
||||
- math
|
||||
library_name: transformers
|
||||
---
|
||||
|
||||
# OpenMath-Nemotron-14B-Kaggle
|
||||
|
||||
OpenMath-Nemotron-14B-Kaggle is created by finetuning [Qwen/Qwen2.5-14B](https://huggingface.co/Qwen/Qwen2.5-14B) on a subset of [OpenMathReasoning](https://huggingface.co/datasets/nvidia/OpenMathReasoning) dataset.
|
||||
This model was used in our first place submission to the [AIMO-2 Kaggle competition](https://www.kaggle.com/competitions/ai-mathematical-olympiad-progress-prize-2/leaderboard)!
|
||||
|
||||

|
||||
|
||||
|
||||
OpenMath-Nemotron models achieve state-of-the-art results on popular mathematical benchmarks. We present metrics as pass@1 (maj@64) where pass@1
|
||||
is an average accuracy across 64 generations and maj@64 is the result of majority voting.
|
||||
Please see our [paper](https://arxiv.org/abs/2504.16891) for more details on the evaluation setup.
|
||||
|
||||
| Model | AIME24 | AIME25 | HMMT-24-25 | HLE-Math |
|
||||
|-------------------------------|-----------------|-------|-------|-------------|
|
||||
| DeepSeek-R1-Distill-Qwen-1.5B | 26.8 (60.0) | 21.4 (36.7) | 14.2 (26.5) | 2.9 (5.0) |
|
||||
| [OpenMath-Nemotron-1.5B](https://huggingface.co/nvidia/OpenMath-Nemotron-1.5B) CoT | 61.6 (80.0) | 49.5 (66.7) | 39.9 (53.6) | 5.4 (5.4) |
|
||||
| [OpenMath-Nemotron-1.5B](https://huggingface.co/nvidia/OpenMath-Nemotron-1.5B) TIR | 52.0 (83.3) | 39.7 (70.0) | 37.2 (60.7) | 2.5 (6.2) |
|
||||
| + Self GenSelect | 83.3 | 70.0 | 62.2 | 7.9 |
|
||||
| + 32B GenSelect | 83.3 | 70.0 | 62.8 | 8.3 |
|
||||
| DeepSeek-R1-Distill-Qwen-7B | 54.4 (80.0) | 38.6 (53.3) | 30.6 (42.9) | 3.3 (5.2) |
|
||||
| [OpenMath-Nemotron-7B](https://huggingface.co/nvidia/OpenMath-Nemotron-7B) CoT | 74.8 (80.0) | 61.2 (76.7) | 49.7 (57.7) | 6.6 (6.6) |
|
||||
| [OpenMath-Nemotron-7B](https://huggingface.co/nvidia/OpenMath-Nemotron-7B) TIR | 72.9 (83.3) | 57.5 (76.7) | 54.6 (66.3) | 7.8 (10.8) |
|
||||
| + Self GenSelect | 86.7 | 76.7 | 68.4 | 11.5 |
|
||||
| + 32B GenSelect | 86.7 | 76.7 | 69.9 | 11.9 |
|
||||
| DeepSeek-R1-Distill-Qwen-14B | 65.8 (80.0) | 48.4 (60.0) | 40.1 (52.0) | 4.2 (4.8) |
|
||||
| [OpenMath-Nemotron-14B-MIX (kaggle)](https://huggingface.co/nvidia/OpenMath-Nemotron-14B-Kaggle) | 73.7 (86.7) | 57.9 (73.3) | 50.5 (64.8) | 5.7 (6.5) |
|
||||
| [OpenMath-Nemotron-14B](https://huggingface.co/nvidia/OpenMath-Nemotron-14B) CoT | 76.3 (83.3) | 63.0 (76.7) | 52.1 (60.7) | 7.5 (7.6) |
|
||||
| [OpenMath-Nemotron-14B](https://huggingface.co/nvidia/OpenMath-Nemotron-14B) TIR | 76.3 (86.7) | 61.3 (76.7) | 58.6 (70.9) | 9.5 (11.5) |
|
||||
| + Self GenSelect | 86.7 | 76.7 | 72.4 | 14.1 |
|
||||
| + 32B GenSelect | 90.0 | 76.7 | 71.9 | 13.7 |
|
||||
| QwQ-32B | 78.1 (86.7) | 66.5 (76.7) | 55.9 (63.3) | 9.0 (9.5) |
|
||||
| DeepSeek-R1-Distill-Qwen-32B | 66.9 (83.3) | 51.8 (73.3) | 39.9 (51.0) | 4.8 (6.0) |
|
||||
| [OpenMath-Nemotron-32B](https://huggingface.co/nvidia/OpenMath-Nemotron-32B) CoT | 76.5 (86.7) | 62.5 (73.3) | 53.0 (59.2) | 8.3 (8.3) |
|
||||
| [OpenMath-Nemotron-32B](https://huggingface.co/nvidia/OpenMath-Nemotron-32B) TIR | 78.4 (93.3) | 64.2 (76.7) | 59.7 (70.9) | 9.2 (12.5) |
|
||||
| + Self GenSelect | 93.3 | 80.0 | 73.5 | 15.7 |
|
||||
| DeepSeek-R1 | 79.1 (86.7) | 64.3 (73.3) | 53.0 (59.2) | 10.5 (11.4) |
|
||||
|
||||
## Reproducing our results
|
||||
|
||||
The pipeline we used to produce the data and models is fully open-sourced!
|
||||
|
||||
- [Code](https://github.com/NVIDIA/NeMo-Skills)
|
||||
- [Models](https://huggingface.co/collections/nvidia/openmathreasoning-68072c0154a5099573d2e730)
|
||||
- [Dataset](https://huggingface.co/datasets/nvidia/OpenMathReasoning)
|
||||
- [Paper](https://arxiv.org/abs/2504.16891)
|
||||
|
||||
We provide [all instructions](https://nvidia.github.io/NeMo-Skills/openmathreasoning1/)
|
||||
to fully reproduce our results, including data generation.
|
||||
|
||||
## How to use the models?
|
||||
|
||||
This model will always use code execution to solve math problems, so we highly recommend to run inference with our
|
||||
[reference implementation in NeMo-Skills](https://nvidia.github.io/NeMo-Skills/openmathreasoning1/evaluation/).
|
||||
|
||||
Please note that these models have not been instruction tuned on general data and thus might not provide good answers outside of math domain.
|
||||
|
||||
## Citation
|
||||
|
||||
If you find our work useful, please consider citing us!
|
||||
|
||||
```bibtex
|
||||
@article{moshkov2025aimo2,
|
||||
title = {AIMO-2 Winning Solution: Building State-of-the-Art Mathematical Reasoning Models with OpenMathReasoning dataset},
|
||||
author = {Ivan Moshkov and Darragh Hanley and Ivan Sorokin and Shubham Toshniwal and Christof Henkel and Benedikt Schifferer and Wei Du and Igor Gitman},
|
||||
year = {2025},
|
||||
journal = {arXiv preprint arXiv:2504.16891}
|
||||
}
|
||||
```
|
||||
|
||||
## Additional information
|
||||
|
||||
### License/Terms of Use: <br>
|
||||
|
||||
GOVERNING TERMS: Use of this model is governed by [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/legalcode.en).
|
||||
Additional Information: [Apache License Version 2.0](https://huggingface.co/Qwen/Qwen2.5-Math-1.5B/blob/main/LICENSE).
|
||||
|
||||
### Deployment Geography:
|
||||
|
||||
Global <br>
|
||||
|
||||
### Use Case: <br>
|
||||
|
||||
This model is intended to facilitate research in the area of mathematical reasoning.
|
||||
|
||||
|
||||
|
||||
### Release Date: <br>
|
||||
|
||||
Huggingface 04/23/2025 <br>
|
||||
|
||||
### Model Architecture: <br>
|
||||
|
||||
**Architecture Type:** Transformer decoder-only language model <br>
|
||||
|
||||
**Network Architecture:** Qwen2.5 <br>
|
||||
|
||||
|
||||
**This model was developed based on Qwen2.5-1.5B <br>
|
||||
|
||||
** This model has 1.5B of model parameters. <br>
|
||||
|
||||
### Input: <br>
|
||||
|
||||
**Input Type(s):** Text <br>
|
||||
|
||||
**Input Format(s):** String <br>
|
||||
|
||||
**Input Parameters:** One-Dimensional (1D) <br>
|
||||
|
||||
**Other Properties Related to Input:** Context length up to 131,072 tokens <br>
|
||||
|
||||
|
||||
|
||||
### Output: <br>
|
||||
|
||||
**Output Type(s):** Text <br>
|
||||
|
||||
**Output Format:** String <br>
|
||||
|
||||
**Output Parameters:** One-Dimensional (1D) <br>
|
||||
|
||||
**Other Properties Related to Output:** Context length up to 131,072 tokens <br>
|
||||
|
||||
|
||||
|
||||
Our AI models are designed and/or optimized to run on NVIDIA GPU-accelerated systems. By leveraging NVIDIA’s hardware (e.g. GPU cores) and software frameworks (e.g., CUDA libraries), the model achieves faster training and inference times compared to CPU-only solutions. <br>
|
||||
|
||||
|
||||
|
||||
### Software Integration : <br>
|
||||
|
||||
**Runtime Engine(s):** <br>
|
||||
|
||||
* Tensor RT / Triton <br>
|
||||
|
||||
|
||||
|
||||
**Supported Hardware Microarchitecture Compatibility:** <br>
|
||||
|
||||
* NVIDIA Ampere <br>
|
||||
|
||||
* NVIDIA Hopper <br>
|
||||
|
||||
|
||||
|
||||
**Preferred Operating System(s):** <br>
|
||||
|
||||
* Linux <br>
|
||||
|
||||
|
||||
|
||||
### Model Version(s):
|
||||
|
||||
[OpenMath-Nemotron-1.5B](https://huggingface.co/nvidia/OpenMath-Nemotron-1.5B)
|
||||
|
||||
[OpenMath-Nemotron-7B](https://huggingface.co/nvidia/OpenMath-Nemotron-7B)
|
||||
|
||||
[OpenMath-Nemotron-14B](https://huggingface.co/nvidia/OpenMath-Nemotron-14B)
|
||||
|
||||
[OpenMath-Nemotron-32B](https://huggingface.co/nvidia/OpenMath-Nemotron-32B)
|
||||
|
||||
|
||||
# Ethical Considerations:
|
||||
|
||||
NVIDIA believes Trustworthy AI is a shared responsibility and we have established policies and practices to enable development for a wide array of AI applications. When downloaded or used in accordance with our terms of service, developers should work with their internal model team to ensure this model meets requirements for the relevant industry and use case and addresses unforeseen product misuse.
|
||||
|
||||
For more detailed information on ethical considerations for this model, please see the Model Card++ [Explainability](./EXPLAINABILITY.md), [Bias](./BIAS.md), [Safety & Security](./SAFETY.md), and [Privacy](./PRIVACY.md) Subcards.
|
||||
|
||||
Please report security vulnerabilities or NVIDIA AI Concerns [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
|
||||
6
SAFETY.md
Normal file
6
SAFETY.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Field | Response
|
||||
:---------------------------------------------------|:----------------------------------
|
||||
Model Application(s): | Text generation, reasoning, solving mathematical problems.
|
||||
Use Case Restrictions: | Use of this model is governed by [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/) license
|
||||
Model and dataset restrictions: | The Principle of least privilege (PoLP) is applied limiting access for dataset generation. Restrictions enforce dataset access during training, and dataset license constraints adhered to. Model checkpoints are made available on Hugging Face.
|
||||
Use Case Restrictions: | Use of this model is governed by [CC-BY-4.0]((https://creativecommons.org/licenses/by/4.0/)) license. Additional Information: [Apache License Version 2.0](https://huggingface.co/Qwen/Qwen2.5-Math-1.5B/blob/main/LICENSE)
|
||||
31
config.json
Normal file
31
config.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"_name_or_path": "nvidia/OpenMath-Nemotron-14B-Kaggle",
|
||||
"architectures": [
|
||||
"Qwen2ForCausalLM"
|
||||
],
|
||||
"attention_dropout": 0.0,
|
||||
"bos_token_id": 151643,
|
||||
"classifier_dropout": 0.0,
|
||||
"eos_token_id": 151645,
|
||||
"hidden_act": "silu",
|
||||
"hidden_dropout": 0.0,
|
||||
"hidden_size": 5120,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 13824,
|
||||
"max_position_embeddings": 131072,
|
||||
"max_window_layers": 70,
|
||||
"model_type": "qwen2",
|
||||
"num_attention_heads": 40,
|
||||
"num_hidden_layers": 48,
|
||||
"num_key_value_heads": 8,
|
||||
"rms_norm_eps": 1e-06,
|
||||
"rope_scaling": null,
|
||||
"rope_theta": 1000000.0,
|
||||
"sliding_window": null,
|
||||
"tie_word_embeddings": false,
|
||||
"torch_dtype": "bfloat16",
|
||||
"transformers_version": "4.48.0.dev0",
|
||||
"use_cache": true,
|
||||
"use_sliding_window": false,
|
||||
"vocab_size": 152064
|
||||
}
|
||||
1
configuration.json
Normal file
1
configuration.json
Normal file
@@ -0,0 +1 @@
|
||||
{"framework": "pytorch", "task": "text-generation", "allow_remote": true}
|
||||
32
entrypoint.sh
Normal file
32
entrypoint.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Default environment variables
|
||||
export MODEL_PATH=${MODEL_PATH:-"/repository"}
|
||||
|
||||
echo "Starting NeMo Skills inference endpoint..."
|
||||
echo "Model path: $MODEL_PATH"
|
||||
|
||||
# Function to handle cleanup on exit
|
||||
cleanup() {
|
||||
echo "Cleaning up processes..."
|
||||
kill $(jobs -p) 2>/dev/null || true
|
||||
wait
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
# Start the model server in the background
|
||||
echo "Starting model server..."
|
||||
ns start_server \
|
||||
--model="$MODEL_PATH" \
|
||||
--server_gpus=2 \
|
||||
--server_type=vllm \
|
||||
--with_sandbox &
|
||||
|
||||
# Start the HTTP endpoint
|
||||
echo "Starting HTTP endpoint on port 80..."
|
||||
python /usr/local/endpoint/server.py &
|
||||
|
||||
# Wait for both processes
|
||||
echo "Both servers started. Waiting..."
|
||||
wait
|
||||
139
handler.py
Normal file
139
handler.py
Normal file
@@ -0,0 +1,139 @@
|
||||
import os
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Dict, List, Any
|
||||
|
||||
from nemo_skills.inference.server.code_execution_model import get_code_execution_model
|
||||
from nemo_skills.code_execution.sandbox import get_sandbox
|
||||
from nemo_skills.prompt.utils import get_prompt
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EndpointHandler:
|
||||
"""Custom endpoint handler for NeMo Skills code execution inference."""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize the handler with the model and prompt configurations.
|
||||
"""
|
||||
self.model = None
|
||||
self.prompt = None
|
||||
self.initialized = False
|
||||
|
||||
# Configuration
|
||||
self.prompt_config_path = os.getenv("PROMPT_CONFIG_PATH", "generic/math")
|
||||
self.prompt_template_path = os.getenv("PROMPT_TEMPLATE_PATH", "openmath-instruct")
|
||||
|
||||
def _initialize_components(self):
|
||||
"""Initialize the model, sandbox, and prompt components lazily."""
|
||||
if self.initialized:
|
||||
return
|
||||
|
||||
try:
|
||||
logger.info("Initializing sandbox...")
|
||||
sandbox = get_sandbox(sandbox_type="local")
|
||||
|
||||
logger.info("Initializing code execution model...")
|
||||
self.model = get_code_execution_model(
|
||||
server_type="vllm",
|
||||
sandbox=sandbox,
|
||||
host="127.0.0.1",
|
||||
port=5000
|
||||
)
|
||||
|
||||
logger.info("Initializing prompt...")
|
||||
if self.prompt_config_path:
|
||||
self.prompt = get_prompt(
|
||||
prompt_config=self.prompt_config_path,
|
||||
prompt_template=self.prompt_template_path
|
||||
)
|
||||
|
||||
self.initialized = True
|
||||
logger.info("All components initialized successfully")
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize the model")
|
||||
|
||||
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Process inference requests.
|
||||
|
||||
Args:
|
||||
data: Dictionary containing the request data
|
||||
Expected keys:
|
||||
- inputs: str or list of str - the input prompts/problems
|
||||
- parameters: dict (optional) - generation parameters
|
||||
|
||||
Returns:
|
||||
List of dictionaries containing the generated responses
|
||||
"""
|
||||
try:
|
||||
# Initialize components if not already done
|
||||
self._initialize_components()
|
||||
|
||||
# Extract inputs and parameters
|
||||
inputs = data.get("inputs", "")
|
||||
parameters = data.get("parameters", {})
|
||||
|
||||
# Handle both single string and list of strings
|
||||
if isinstance(inputs, str):
|
||||
prompts = [inputs]
|
||||
elif isinstance(inputs, list):
|
||||
prompts = inputs
|
||||
else:
|
||||
raise ValueError("inputs must be a string or list of strings")
|
||||
|
||||
# If we have a prompt template configured, format the inputs
|
||||
if self.prompt is not None:
|
||||
formatted_prompts = []
|
||||
for prompt_text in prompts:
|
||||
formatted_prompt = self.prompt.fill({"problem": prompt_text, "total_code_executions": 8})
|
||||
formatted_prompts.append(formatted_prompt)
|
||||
prompts = formatted_prompts
|
||||
|
||||
# Get code execution arguments from prompt if available
|
||||
extra_generate_params = {}
|
||||
if self.prompt is not None:
|
||||
extra_generate_params = self.prompt.get_code_execution_args()
|
||||
|
||||
# Set default generation parameters
|
||||
generation_params = {
|
||||
"tokens_to_generate": 12000,
|
||||
"temperature": 0.0,
|
||||
"top_p": 0.95,
|
||||
"top_k": 0,
|
||||
"repetition_penalty": 1.0,
|
||||
"random_seed": 0,
|
||||
}
|
||||
|
||||
# Update with provided parameters
|
||||
generation_params.update(parameters)
|
||||
generation_params.update(extra_generate_params)
|
||||
|
||||
logger.info(f"Processing {len(prompts)} prompt(s)")
|
||||
|
||||
# Generate responses
|
||||
outputs = self.model.generate(
|
||||
prompts=prompts,
|
||||
**generation_params
|
||||
)
|
||||
|
||||
# Format outputs
|
||||
results = []
|
||||
for output in outputs:
|
||||
result = {
|
||||
"generated_text": output.get("generation", ""),
|
||||
"code_rounds_executed": output.get("code_rounds_executed", 0),
|
||||
}
|
||||
results.append(result)
|
||||
|
||||
logger.info(f"Successfully processed {len(results)} request(s)")
|
||||
return results
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing request: {str(e)}")
|
||||
logger.error(traceback.format_exc())
|
||||
return [{"error": str(e), "generated_text": ""}]
|
||||
9
mergekit_config.yml
Normal file
9
mergekit_config.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
models:
|
||||
- model: /models/14b-code-execution-15k-400steps-lr1e-5-2-blocks
|
||||
parameters:
|
||||
weight: 0.7
|
||||
- model: /models/14b-r1-sdg-all-public-2m-8epochs-lr1e-4-minlr1e-7-warm1600
|
||||
parameters:
|
||||
weight: 0.3
|
||||
merge_method: linear
|
||||
dtype: bfloat16
|
||||
151388
merges.txt
Normal file
151388
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model-00001-of-00006.safetensors
Normal file
3
model-00001-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c187158b799fe136883051e8549cbf96b47ed86bc602d49aff4cb7e2417db53c
|
||||
size 4907454960
|
||||
3
model-00002-of-00006.safetensors
Normal file
3
model-00002-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ed313e1e53c2290a03157d0ad0f0332ddc4488690ed4dcfaae168149ab21fd4c
|
||||
size 4954847384
|
||||
3
model-00003-of-00006.safetensors
Normal file
3
model-00003-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:729aea2932f6da2e7169d13f41fd1faf667b9e4fbdcce2f6d9b1a279c7dc746b
|
||||
size 4954847376
|
||||
3
model-00004-of-00006.safetensors
Normal file
3
model-00004-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b8fc2ebea310a8233f1253b8599b9ca4cdfbfbd2edf1b66ea9a482534c639937
|
||||
size 4954847376
|
||||
3
model-00005-of-00006.safetensors
Normal file
3
model-00005-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:67756a066698da8393bc2013938f25b49d350f899a189566403a4b05cbab5260
|
||||
size 4954847376
|
||||
3
model-00006-of-00006.safetensors
Normal file
3
model-00006-of-00006.safetensors
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:995bb839c0536f87f6dc94a55c4ff7c1eb30113523992a618ca8d4e7806676f2
|
||||
size 4813289432
|
||||
1
model.safetensors.index.json
Normal file
1
model.safetensors.index.json
Normal file
File diff suppressed because one or more lines are too long
BIN
results.png
Normal file
BIN
results.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 214 KiB |
77
server.py
Normal file
77
server.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import json
|
||||
import logging
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
from handler import EndpointHandler
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Initialize the handler
|
||||
handler = EndpointHandler()
|
||||
|
||||
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
try:
|
||||
content_length = int(self.headers['Content-Length'])
|
||||
post_data = self.rfile.read(content_length)
|
||||
data = json.loads(post_data.decode('utf-8'))
|
||||
|
||||
logger.info(f'Received request with {len(data.get("inputs", []))} inputs')
|
||||
|
||||
# Process the request
|
||||
result = handler(data)
|
||||
|
||||
# Send response
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(result).encode('utf-8'))
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f'Error processing request: {str(e)}')
|
||||
self.send_response(500)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
error_response = [{'error': str(e), 'generated_text': ''}]
|
||||
self.wfile.write(json.dumps(error_response).encode('utf-8'))
|
||||
|
||||
def do_GET(self):
|
||||
if self.path == '/health':
|
||||
# Trigger initialisation if needed but don't block.
|
||||
if not handler.initialized:
|
||||
try:
|
||||
handler._initialize_components()
|
||||
except Exception as e:
|
||||
logger.error(f'Initialization failed during health check: {str(e)}')
|
||||
|
||||
is_ready = handler.initialized
|
||||
health_response = {
|
||||
'status': 'healthy' if is_ready else 'unhealthy',
|
||||
'model_ready': is_ready
|
||||
}
|
||||
|
||||
try:
|
||||
self.send_response(200 if is_ready else 503)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(health_response).encode('utf-8'))
|
||||
except BrokenPipeError:
|
||||
# Client disconnected before we replied – safe to ignore.
|
||||
pass
|
||||
return
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, format, *args):
|
||||
# Suppress default HTTP server logs to keep output clean
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
server = HTTPServer(('0.0.0.0', 80), RequestHandler)
|
||||
logger.info('HTTP server started on port 80')
|
||||
server.serve_forever()
|
||||
31
special_tokens_map.json
Normal file
31
special_tokens_map.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|object_ref_start|>",
|
||||
"<|object_ref_end|>",
|
||||
"<|box_start|>",
|
||||
"<|box_end|>",
|
||||
"<|quad_start|>",
|
||||
"<|quad_end|>",
|
||||
"<|vision_start|>",
|
||||
"<|vision_end|>",
|
||||
"<|vision_pad|>",
|
||||
"<|image_pad|>",
|
||||
"<|video_pad|>"
|
||||
],
|
||||
"eos_token": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
},
|
||||
"pad_token": {
|
||||
"content": "<|endoftext|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false
|
||||
}
|
||||
}
|
||||
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
|
||||
size 11421896
|
||||
208
tokenizer_config.json
Normal file
208
tokenizer_config.json
Normal file
@@ -0,0 +1,208 @@
|
||||
{
|
||||
"add_bos_token": false,
|
||||
"add_prefix_space": false,
|
||||
"added_tokens_decoder": {
|
||||
"151643": {
|
||||
"content": "<|endoftext|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151644": {
|
||||
"content": "<|im_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151645": {
|
||||
"content": "<|im_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151646": {
|
||||
"content": "<|object_ref_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151647": {
|
||||
"content": "<|object_ref_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151648": {
|
||||
"content": "<|box_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151649": {
|
||||
"content": "<|box_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151650": {
|
||||
"content": "<|quad_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151651": {
|
||||
"content": "<|quad_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151652": {
|
||||
"content": "<|vision_start|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151653": {
|
||||
"content": "<|vision_end|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151654": {
|
||||
"content": "<|vision_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151655": {
|
||||
"content": "<|image_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151656": {
|
||||
"content": "<|video_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"151657": {
|
||||
"content": "<tool_call>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151658": {
|
||||
"content": "</tool_call>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151659": {
|
||||
"content": "<|fim_prefix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151660": {
|
||||
"content": "<|fim_middle|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151661": {
|
||||
"content": "<|fim_suffix|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151662": {
|
||||
"content": "<|fim_pad|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151663": {
|
||||
"content": "<|repo_name|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
},
|
||||
"151664": {
|
||||
"content": "<|file_sep|>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": false
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<|object_ref_start|>",
|
||||
"<|object_ref_end|>",
|
||||
"<|box_start|>",
|
||||
"<|box_end|>",
|
||||
"<|quad_start|>",
|
||||
"<|quad_end|>",
|
||||
"<|vision_start|>",
|
||||
"<|vision_end|>",
|
||||
"<|vision_pad|>",
|
||||
"<|image_pad|>",
|
||||
"<|video_pad|>"
|
||||
],
|
||||
"bos_token": null,
|
||||
"chat_template": "{%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}\n{%- else %}\n {{- '<|im_start|>system\n<|im_end|>\n' }}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == 'user') or (message.role == 'system' and not loop.first) or (message.role == 'assistant') %}\n {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\n' }}\n{%- endif %}",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "<|im_end|>",
|
||||
"errors": "replace",
|
||||
"extra_special_tokens": {},
|
||||
"model_max_length": 131072,
|
||||
"pad_token": "<|endoftext|>",
|
||||
"split_special_tokens": false,
|
||||
"tokenizer_class": "Qwen2Tokenizer",
|
||||
"unk_token": null
|
||||
}
|
||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user