Instructions to use xiaohang07/MatterGPT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xiaohang07/MatterGPT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="xiaohang07/MatterGPT")# Load model directly from transformers import GPT model = GPT.from_pretrained("xiaohang07/MatterGPT", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use xiaohang07/MatterGPT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xiaohang07/MatterGPT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xiaohang07/MatterGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/xiaohang07/MatterGPT
- SGLang
How to use xiaohang07/MatterGPT 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 "xiaohang07/MatterGPT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xiaohang07/MatterGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "xiaohang07/MatterGPT" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xiaohang07/MatterGPT", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use xiaohang07/MatterGPT with Docker Model Runner:
docker model run hf.co/xiaohang07/MatterGPT
| from mattergpt_wrapper import MatterGPTWrapper, SimpleTokenizer | |
| import torch | |
| from tqdm import tqdm | |
| import os | |
| import logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| # Load the model | |
| model_path = "./" # Directory containing config.json and pytorch_model.bin | |
| if not os.path.exists(os.path.join(model_path, "config.json")): | |
| raise FileNotFoundError(f"Config file not found in {model_path}") | |
| if not os.path.exists(os.path.join(model_path, "pytorch_model.pt")): | |
| raise FileNotFoundError(f"Model weights not found in {model_path}") | |
| model = MatterGPTWrapper.from_pretrained(model_path) | |
| model.to('cuda' if torch.cuda.is_available() else 'cpu') | |
| logger.info(f"Model loaded from {model_path}") | |
| # Load the tokenizer | |
| tokenizer_path = "Voc_prior" | |
| if not os.path.exists(tokenizer_path): | |
| raise FileNotFoundError(f"Tokenizer vocabulary file not found at {tokenizer_path}") | |
| tokenizer = SimpleTokenizer(tokenizer_path) | |
| logger.info(f"Tokenizer loaded from {tokenizer_path}") | |
| # Function to generate a single sequence | |
| def generate_single(condition): | |
| context = '>' | |
| x = torch.tensor([tokenizer.stoi[context]], dtype=torch.long)[None,...].to(model.device) | |
| p = torch.tensor([condition]).unsqueeze(1).to(model.device) | |
| generated = model.generate(x, prop=p, max_length=model.config.block_size, temperature=1.2, do_sample=True, top_k=0, top_p=0.9) | |
| return tokenizer.decode(generated[0].tolist()) | |
| # Function to generate multiple sequences | |
| def generate_multiple(condition, num_sequences, batch_size=32): | |
| all_sequences = [] | |
| for _ in tqdm(range(0, num_sequences, batch_size)): | |
| current_batch_size = min(batch_size, num_sequences - len(all_sequences)) | |
| context = '>' | |
| x = torch.tensor([tokenizer.stoi[context]], dtype=torch.long)[None,...].repeat(current_batch_size, 1).to(model.device) | |
| p = torch.tensor([condition]).repeat(current_batch_size, 1).unsqueeze(1).to(model.device) | |
| generated = model.generate(x, prop=p, max_length=model.config.block_size, temperature=1.2, do_sample=True, top_k=0, top_p=0.9) | |
| all_sequences.extend([tokenizer.decode(seq.tolist()) for seq in generated]) | |
| if len(all_sequences) >= num_sequences: | |
| break | |
| return all_sequences[:num_sequences] | |
| # Example usage | |
| condition = [-1.0, 2.0] # eform and bandgap | |
| # Generate a single sequence | |
| logger.info("Generating a single sequence:") | |
| single_sequence = generate_single(condition) | |
| print(single_sequence) | |
| print() | |
| # Generate multiple sequences | |
| num_sequences = 10 | |
| logger.info(f"Generating {num_sequences} sequences:") | |
| multiple_sequences = generate_multiple(condition, num_sequences) | |
| for i, seq in enumerate(multiple_sequences, 1): | |
| print(seq) | |
| logger.info("Generation complete") |