Text Generation
Transformers
Safetensors
English
qwen2
nvidia
math
conversational
text-generation-inference
Instructions to use nvidia/OpenMath-Nemotron-14B-Kaggle with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nvidia/OpenMath-Nemotron-14B-Kaggle with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nvidia/OpenMath-Nemotron-14B-Kaggle") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("nvidia/OpenMath-Nemotron-14B-Kaggle") model = AutoModelForCausalLM.from_pretrained("nvidia/OpenMath-Nemotron-14B-Kaggle", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nvidia/OpenMath-Nemotron-14B-Kaggle with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nvidia/OpenMath-Nemotron-14B-Kaggle" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/OpenMath-Nemotron-14B-Kaggle", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nvidia/OpenMath-Nemotron-14B-Kaggle
- SGLang
How to use nvidia/OpenMath-Nemotron-14B-Kaggle with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "nvidia/OpenMath-Nemotron-14B-Kaggle" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/OpenMath-Nemotron-14B-Kaggle", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "nvidia/OpenMath-Nemotron-14B-Kaggle" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nvidia/OpenMath-Nemotron-14B-Kaggle", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use nvidia/OpenMath-Nemotron-14B-Kaggle with Docker Model Runner:
docker model run hf.co/nvidia/OpenMath-Nemotron-14B-Kaggle
File size: 2,683 Bytes
b1a665d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 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() |