Text Generation
Transformers
Safetensors
llama
research
code
mathematics
reasoning
multilingual
long-context
custom_code
text-generation-inference
Run this model with HF Jobs
Run DeepXR/Helion-V2.5-Rnd on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/DeepXR/Helion-V2.5-Rnd. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/DeepXR/Helion-V2.5-Rnd on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/DeepXR/Helion-V2.5-Rnd. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/DeepXR/Helion-V2.5-Rnd. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use DeepXR/Helion-V2.5-Rnd with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DeepXR/Helion-V2.5-Rnd with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DeepXR/Helion-V2.5-Rnd", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("DeepXR/Helion-V2.5-Rnd", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("DeepXR/Helion-V2.5-Rnd", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DeepXR/Helion-V2.5-Rnd with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DeepXR/Helion-V2.5-Rnd" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeepXR/Helion-V2.5-Rnd", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/DeepXR/Helion-V2.5-Rnd
- SGLang
How to use DeepXR/Helion-V2.5-Rnd 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 "DeepXR/Helion-V2.5-Rnd" \ --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": "DeepXR/Helion-V2.5-Rnd", "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 "DeepXR/Helion-V2.5-Rnd" \ --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": "DeepXR/Helion-V2.5-Rnd", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use DeepXR/Helion-V2.5-Rnd with Docker Model Runner:
docker model run hf.co/DeepXR/Helion-V2.5-Rnd
Create inference/data_loader.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510#!/usr/bin/env python3"""Helion-2.5-Rnd Advanced Data LoaderEfficient data loading and preprocessing for inference"""
import jsonimport loggingfrom pathlib import Pathfrom typing import Any, Dict, Iterator, List, Optional, Union
import numpy as npfrom safetensors.torch import load_file
logging.basicConfig(level=logging.INFO)logger = logging.getLogger(__name__)
class SafeTensorsLoader: """Efficient SafeTensors model loading with validation""" def __init__(self, model_path: str, device: str = "cuda"): """ Initialize SafeTensors loader Args: model_path: Path to model directory device: Target device for loading """ self.model_path = Path(model_path) self.device = device self.index = self._load_index() self.loaded_shards = {} def _load_index(self) -> Dict: """Load SafeTensors index file""" index_path = self.model_path / "model.safetensors.index.json" if not index_path.exists(): raise FileNotFoundError(f"Index file not found: {index_path}") with open(index_path, 'r') as f: index = json.load(f) logger.info(f"Loaded index with {len(index.get('weight_map', {}))} weight mappings") return index def get_shard_path(self, shard_name: str) -> Path: """Get full path to shard file""" return self.model_path / shard_name def load_shard(self, shard_name: str, lazy: bool = False) -> Dict: """ Load a single SafeTensors shard Args: shard_name: Name of shard file lazy: Whether to use lazy loading Returns: Dictionary of tensors """ if shard_name in self.loaded_shards: logger.debug(f"Using cached shard: {shard_name}") return self.loaded_shards[shard_name] shard_path = self.get_shard_path(shard_name) if not shard_path.exists(): raise FileNotFoundError(f"Shard not found: {shard_path}") logger.info(f"Loading shard: {shard_name}") try: tensors = load_file(str(shard_path), device=self.device) if not lazy: self.loaded_shards[shard_name] = tensors return tensors except Exception as e: logger.error(f"Failed to load shard {shard_name}: {e}") raise def load_weight(self, weight_name: str) -> Any: """ Load a specific weight by name Args: weight_name: Name of the weight tensor Returns: Weight tensor """ weight_map = self.index.get('weight_map', {}) if weight_name not in weight_map: raise KeyError(f"Weight not found in index: {weight_name}") shard_name = weight_map[weight_name] tensors = self.load_shard(shard_name) return tensors[weight_name] def load_all_weights(self, progress_callback=None) -> Dict: """ Load all model weights Args: progress_callback: Optional callback for progress updates Returns: Dictionary of all weights """ all_weights = {} weight_map = self.index.get('weight_map', {}) unique_shards = set(weight_map.values()) logger.info(f"Loading {len(unique_shards)} shards...") for i, shard_name in enumerate(sorted(unique_shards)): tensors = self.load_shard(shard_name) all_weights.update(tensors) if progress_callback: progress_callback(i + 1, len(unique_shards)) logger.info(f"Loaded {len(all_weights)} weight tensors") return all_weights def validate_checksums(self) -> Dict[str, bool]: """ Validate SHA256 checksums of all shards Returns: Dictionary mapping shard names to validation status """ import hashlib results = {} file_metadata = self.index.get('file_metadata', {}) for shard_name, metadata in file_metadata.items(): expected_hash = metadata.get('sha256') if not expected_hash: results[shard_name] = None continue shard_path = self.get_shard_path(shard_name) if not shard_path.exists(): results[shard_name] = False continue sha256 = hashlib.sha256() with open(shard_path, 'rb') as f: for chunk in iter(lambda: f.read(4096), b''): sha256.update(chunk) actual_hash = sha256.hexdigest() results[shard_name] = (actual_hash == expected_hash) status = "✓" if results[shard_name] else "✗" logger.info(f"{status} {shard_name}") return results def get_model_info(self) -> Dict: """Get model information from index""" metadata = self.index.get('metadata', {}) return { 'model_name': metadata.get('model_name', 'Unknown'), 'version': metadata.get('version', 'Unknown'), 'total_size_bytes': metadata.get('total_size', 0), 'total_size_gb': metadata.get('total_size', 0) / (1024**3), 'format': metadata.get('format', 'safetensors'), 'precision': metadata.get('precision', 'unknown'), 'total_shards': metadata.get('total_shards', 0), 'parameters': metadata.get('parameters', 'Unknown') } def clear_cache(self): """Clear loaded shard cache""" self.loaded_shards.clear() logger.info("Cleared shard cache")
class DatasetPreprocessor: """Preprocess datasets for inference""" def __init__(self, tokenizer=None, max_length: int = 131072): """ Initialize preprocessor Args: tokenizer: Tokenizer instance max_length: Maximum sequence length """ self.tokenizer = tokenizer self.max_length = max_length def preprocess_text(self, text: str) -> str: """ Preprocess raw text Args: text: Input text Returns: Preprocessed text """ # Remove excessive whitespace text = ' '.join(text.split()) # Remove control characters text = ''.join(char for char in text if ord(char) >= 32 or char in '\n\t') return text.strip() def preprocess_chat_messages(self, messages: List[Dict[str, str]]) -> str: """ Preprocess chat messages into prompt format Args: messages: List of message dictionaries Returns: Formatted prompt string """ formatted = "" for msg in messages: role = msg.get('role', 'user') content = self.preprocess_text(msg.get('content', '')) formatted += f"<|im_start|>{role}\n{content}<|im_end|>\n" formatted += "<|im_start|>assistant\n" return formatted def batch_preprocess( self, texts: List[str], add_special_tokens: bool = True, padding: bool = True, truncation: bool = True ) -> Dict: """ Batch preprocess texts Args: texts: List of input texts add_special_tokens: Whether to add special tokens padding: Whether to pad sequences truncation: Whether to truncate sequences Returns: Batch of preprocessed data """ if self.tokenizer is None: raise ValueError("Tokenizer not initialized") processed_texts = [self.preprocess_text(text) for text in texts] encodings = self.tokenizer( processed_texts, add_special_tokens=add_special_tokens, padding=padding, truncation=truncation, max_length=self.max_length, return_tensors='pt' ) return encodings def stream_process_file( self, file_path: str, batch_size: int = 32 ) -> Iterator[Dict]: """ Stream process large files in batches Args: file_path: Path to input file batch_size: Number of samples per batch Yields: Batches of preprocessed data """ path = Path(file_path) if path.suffix == '.jsonl': with open(path, 'r') as f: batch = [] for line in f: try: data = json.loads(line) text = data.get('text', '') batch.append(text) if len(batch) >= batch_size: yield self.batch_preprocess(batch) batch = [] except json.JSONDecodeError: logger.warning(f"Skipping invalid JSON line") if batch: yield self.batch_preprocess(batch) elif path.suffix == '.txt': with open(path, 'r') as f: batch = [] for line in f: batch.append(line.strip()) if len(batch) >= batch_size: yield self.batch_preprocess(batch) batch = [] if batch: yield self.batch_preprocess(batch) else: raise ValueError(f"Unsupported file format: {path.suffix}")
class InferenceDataCollator: """Collate data for efficient batch inference""" def __init__(self, pad_token_id: int = 128001): """ Initialize data collator Args: pad_token_id: ID for padding token """ self.pad_token_id = pad_token_id def __call__(self, features: List[Dict]) -> Dict: """ Collate features into batch Args: features: List of feature dictionaries Returns: Batched features """ if not features: return {} # Get maximum sequence length in batch max_length = max(len(f['input_ids']) for f in features) batch = { 'input_ids': [], 'attention_mask': [] } for feature in features: input_ids = feature['input_ids'] attention_mask = feature.get('attention_mask', [1] * len(input_ids)) # Pad to max length padding_length = max_length - len(input_ids) input_ids = input_ids + [self.pad_token_id] * padding_length attention_mask = attention_mask + [0] * padding_length batch['input_ids'].append(input_ids) batch['attention_mask'].append(attention_mask) # Convert to numpy arrays batch['input_ids'] = np.array(batch['input_ids'], dtype=np.int64) batch['attention_mask'] = np.array(batch['attention_mask'], dtype=np.int64) return batch def dynamic_padding(self, features: List[Dict], padding_multiple: int = 8) -> Dict: """ Apply dynamic padding optimized for hardware Args: features: List of feature dictionaries padding_multiple: Pad to multiple of this value Returns: Batched features with optimal padding """ if not features: return {} max_length = max(len(f['input_ids']) for f in features) # Round up to nearest multiple padded_length = ((max_length + padding_multiple - 1) // padding_multiple) * padding_multiple batch = { 'input_ids': [], 'attention_mask': [] } for feature in features: input_ids = feature['input_ids'] attention_mask = feature.get('attention_mask', [1] * len(input_ids)) padding_length = padded_length - len(input_ids) input_ids = input_ids + [self.pad_token_id] * padding_length attention_mask = attention_mask + [0] * padding_length batch['input_ids'].append(input_ids) batch['attention_mask'].append(attention_mask) batch['input_ids'] = np.array(batch['input_ids'], dtype=np.int64) batch['attention_mask'] = np.array(batch['attention_mask'], dtype=np.int64) return batch
class CachedDataLoader: """Data loader with caching for repeated inference""" def __init__(self, cache_dir: str = "./cache"): """ Initialize cached data loader Args: cache_dir: Directory for cache storage """ self.cache_dir = Path(cache_dir) self.cache_dir.mkdir(parents=True, exist_ok=True) def get_cache_key(self, text: str) -> str: """Generate cache key from text""" import hashlib return hashlib.sha256(text.encode()).hexdigest() def load_from_cache(self, cache_key: str) -> Optional[Any]: """ Load data from cache Args: cache_key: Cache identifier Returns: Cached data or None """ cache_path = self.cache_dir / f"{cache_key}.json" if not cache_path.exists(): return None try: with open(cache_path, 'r') as f: return json.load(f) except Exception as e: logger.warning(f"Failed to load from cache: {e}") return None def save_to_cache(self, cache_key: str, data: Any): """ Save data to cache Args: cache_key: Cache identifier data: Data to cache """ cache_path = self.cache_dir / f"{cache_key}.json" try: with open(cache_path, 'w') as f: json.dump(data, f) except Exception as e: logger.warning(f"Failed to save to cache: {e}") def clear_cache(self): """Clear all cached data""" import shutil shutil.rmtree(self.cache_dir) self.cache_dir.mkdir(parents=True, exist_ok=True) logger.info("Cache cleared")
def main(): """Example usage""" # SafeTensors loading loader = SafeTensorsLoader("./models/helion") # Get model info info = loader.get_model_info() print(f"Model: {info['model_name']}") print(f"Size: {info['total_size_gb']:.2f} GB") print(f"Shards: {info['total_shards']}") # Validate checksums print("\nValidating checksums...") results = loader.validate_checksums() valid_count = sum(1 for v in results.values() if v) print(f"Valid: {valid_count}/{len(results)}")
if __name__ == "__main__": main()inference/data_loader.pyAdded+510