Text Generation
Transformers
PyTorch
English
shram
research
sparse-attention
mixture-of-experts
custom_code
Instructions to use smithblack-0/SHRAM-dev with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use smithblack-0/SHRAM-dev with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="smithblack-0/SHRAM-dev", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("smithblack-0/SHRAM-dev", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use smithblack-0/SHRAM-dev with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "smithblack-0/SHRAM-dev" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "smithblack-0/SHRAM-dev", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/smithblack-0/SHRAM-dev
- SGLang
How to use smithblack-0/SHRAM-dev 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 "smithblack-0/SHRAM-dev" \ --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": "smithblack-0/SHRAM-dev", "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 "smithblack-0/SHRAM-dev" \ --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": "smithblack-0/SHRAM-dev", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use smithblack-0/SHRAM-dev with Docker Model Runner:
docker model run hf.co/smithblack-0/SHRAM-dev
| """Position computation for the MoSRAH sparse path. | |
| This layer computes the packed position tensor P consumed by BEA. | |
| - In main-sequence mode, P is the packed original-token position tensor from the | |
| packing path. | |
| - In semantic-sequence mode, P is a per-expert local sequence over the packed | |
| expert-choice layout, optionally offset by the current sparse-cache occupancies | |
| during cached inference. | |
| """ | |
| import torch | |
| from torch import nn | |
| from .configuration import ShramConfig | |
| from .__cache__mosrah_cache import MoSRAHCache | |
| class SparseMoSRAHPositions(nn.Module): | |
| """Compute the packed RoPE position tensor for the MoSRAH sparse path. | |
| This layer operates in the packed expert-choice frame used by BEA. The input | |
| packed_positions tensor is always the packed original-token position tensor | |
| produced by the packing path. The configured rope_mode determines whether that | |
| tensor is forwarded directly or replaced by a semantic local-slot sequence. | |
| """ | |
| def __init__(self, config: ShramConfig) -> None: | |
| super().__init__() | |
| self.rope_mode = config.rope_mode | |
| def forward( | |
| self, | |
| packed_positions: torch.Tensor, | |
| active_mask: torch.Tensor, | |
| cache: MoSRAHCache | None, | |
| ) -> torch.Tensor: | |
| """Compute the packed position tensor P consumed by BEA. | |
| Args: | |
| packed_positions: Packed original-token positions J' of shape (B, L, T). | |
| active_mask: Boolean active-token mask of shape (B, L, T). Inactive | |
| positions are zeroed in the returned tensor regardless of mode — | |
| their position value is semantically irrelevant and 0 is guaranteed | |
| to be within any valid RoPE table. | |
| cache: Optional layer-local MoSRAH cache. When present in semantic-sequence | |
| mode, the current per-head occupancies offset the local packed sequence. | |
| Returns: | |
| Packed position tensor P of shape (B, L, T). | |
| """ | |
| if self.rope_mode == "main_sequence": | |
| positions = self._main_sequence_positions(packed_positions) | |
| elif self.rope_mode == "semantic_sequence": | |
| positions = self._semantic_sequence_positions(packed_positions, cache) | |
| else: | |
| raise NotImplementedError( | |
| f"Unsupported MoSRAH rope_mode '{self.rope_mode}'." | |
| ) | |
| return torch.where(active_mask, positions, torch.zeros_like(positions)) | |
| def _main_sequence_positions( | |
| self, | |
| packed_positions: torch.Tensor, | |
| ) -> torch.Tensor: | |
| """Forward packed original-token positions unchanged.""" | |
| return packed_positions | |
| def _semantic_sequence_positions( | |
| self, | |
| packed_positions: torch.Tensor, | |
| cache: MoSRAHCache | None, | |
| ) -> torch.Tensor: | |
| """Compute semantic-sequence packed positions in expert-choice space. | |
| Without a sparse cache, semantic positions are the local packed sequence | |
| 0, 1, 2, ... over the expert-local T dimension. With a sparse cache, that | |
| same local sequence is offset by the current per-(batch, expert) occupancies | |
| returned by get_heads_lengths(). | |
| """ | |
| batch_size, num_experts, packed_length = packed_positions.shape | |
| # ------------------------------------------------------------------- | |
| # Construct the local packed sequence 0, 1, 2, ... over the expert-local | |
| # sequence dimension T. This is then broadcast across batch and experts. | |
| # ------------------------------------------------------------------- | |
| local_positions = torch.arange( | |
| packed_length, | |
| device=packed_positions.device, | |
| dtype=packed_positions.dtype, | |
| ).view(1, 1, packed_length).expand( | |
| batch_size, | |
| num_experts, | |
| packed_length, | |
| ) | |
| # ------------------------------------------------------------------- | |
| # In cached semantic-sequence mode, positions continue from the current | |
| # sparse-cache occupancies rather than restarting at zero for the local | |
| # chunk. | |
| # ------------------------------------------------------------------- | |
| if cache is None: | |
| return local_positions | |
| cached_lengths = cache.get_heads_lengths().to( | |
| device=packed_positions.device, | |
| dtype=packed_positions.dtype, | |
| ).unsqueeze(-1) | |
| return local_positions + cached_lengths |