Text Generation
Transformers
Safetensors
English
Chinese
nanbeige
llm
conversational
custom_code
Eval Results
Instructions to use Nanbeige/Nanbeige4.2-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Nanbeige/Nanbeige4.2-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Nanbeige/Nanbeige4.2-3B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Nanbeige/Nanbeige4.2-3B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Nanbeige/Nanbeige4.2-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Nanbeige/Nanbeige4.2-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Nanbeige/Nanbeige4.2-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Nanbeige/Nanbeige4.2-3B
- SGLang
How to use Nanbeige/Nanbeige4.2-3B 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 "Nanbeige/Nanbeige4.2-3B" \ --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": "Nanbeige/Nanbeige4.2-3B", "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 "Nanbeige/Nanbeige4.2-3B" \ --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": "Nanbeige/Nanbeige4.2-3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Nanbeige/Nanbeige4.2-3B with Docker Model Runner:
docker model run hf.co/Nanbeige/Nanbeige4.2-3B
Upload configuration_nanbeige.py
Browse files- configuration_nanbeige.py +70 -16
configuration_nanbeige.py
CHANGED
|
@@ -21,18 +21,14 @@ logger = logging.get_logger(__name__)
|
|
| 21 |
|
| 22 |
class NanbeigeConfig(PretrainedConfig):
|
| 23 |
r"""
|
| 24 |
-
This is the configuration class to store the configuration of a [`NanbeigeModel`]. It is used to instantiate
|
| 25 |
-
|
| 26 |
-
defaults will yield a similar configuration to that of the LLaMA-7B.
|
| 27 |
-
|
| 28 |
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 29 |
documentation from [`PretrainedConfig`] for more information.
|
| 30 |
-
|
| 31 |
-
|
| 32 |
Args:
|
| 33 |
vocab_size (`int`, *optional*, defaults to 32000):
|
| 34 |
-
Vocabulary size of the
|
| 35 |
-
`
|
| 36 |
hidden_size (`int`, *optional*, defaults to 4096):
|
| 37 |
Dimension of the hidden representations.
|
| 38 |
intermediate_size (`int`, *optional*, defaults to 11008):
|
|
@@ -54,8 +50,7 @@ class NanbeigeConfig(PretrainedConfig):
|
|
| 54 |
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 55 |
The non-linear activation function (function or string) in the decoder.
|
| 56 |
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
| 57 |
-
The maximum sequence length that this model might ever be used with.
|
| 58 |
-
Nanbeige 2 up to 4096, CodeNanbeige up to 16384.
|
| 59 |
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 60 |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 61 |
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
|
@@ -128,16 +123,75 @@ class NanbeigeConfig(PretrainedConfig):
|
|
| 128 |
Whether to fuse averaged N-gram embeddings before attention in every decoder layer.
|
| 129 |
ngram_layer_downproject_size (`int`, *optional*):
|
| 130 |
Optional hidden size for N-gram layer fusion projections. If None, fusion uses `hidden_size`.
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
```python
|
| 133 |
>>> from transformers import NanbeigeModel, NanbeigeConfig
|
| 134 |
-
|
| 135 |
-
>>> # Initializing a LLaMA llama-7b style configuration
|
| 136 |
>>> configuration = NanbeigeConfig()
|
| 137 |
-
|
| 138 |
-
>>> # Initializing a model from the llama-7b style configuration
|
| 139 |
>>> model = NanbeigeModel(configuration)
|
| 140 |
-
|
| 141 |
>>> # Accessing the model configuration
|
| 142 |
>>> configuration = model.config
|
| 143 |
```"""
|
|
|
|
| 21 |
|
| 22 |
class NanbeigeConfig(PretrainedConfig):
|
| 23 |
r"""
|
| 24 |
+
This is the configuration class to store the configuration of a [`NanbeigeModel`]. It is used to instantiate a Nanbeige model
|
| 25 |
+
according to the specified arguments, defining the model architecture.
|
|
|
|
|
|
|
| 26 |
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 27 |
documentation from [`PretrainedConfig`] for more information.
|
|
|
|
|
|
|
| 28 |
Args:
|
| 29 |
vocab_size (`int`, *optional*, defaults to 32000):
|
| 30 |
+
Vocabulary size of the Nanbeige model. Defines the number of different tokens that can be represented by the
|
| 31 |
+
`input_ids` passed when calling [`NanbeigeModel`]
|
| 32 |
hidden_size (`int`, *optional*, defaults to 4096):
|
| 33 |
Dimension of the hidden representations.
|
| 34 |
intermediate_size (`int`, *optional*, defaults to 11008):
|
|
|
|
| 50 |
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 51 |
The non-linear activation function (function or string) in the decoder.
|
| 52 |
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
| 53 |
+
The maximum sequence length that this model might ever be used with.
|
|
|
|
| 54 |
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 55 |
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 56 |
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
|
|
|
| 123 |
Whether to fuse averaged N-gram embeddings before attention in every decoder layer.
|
| 124 |
ngram_layer_downproject_size (`int`, *optional*):
|
| 125 |
Optional hidden size for N-gram layer fusion projections. If None, fusion uses `hidden_size`.
|
| 126 |
+
num_loops (`int`, *optional*, defaults to 1):
|
| 127 |
+
Number of times the complete decoder-layer stack is executed with shared parameters. Increasing this value
|
| 128 |
+
increases the model's effective depth and FLOPs without adding a separate set of decoder-layer weights.
|
| 129 |
+
This value is ignored when `loop_loss_weights` is non-empty or `enable_double_loop_split=True`.
|
| 130 |
+
loop_loss_weights (`List[float]`, *optional*):
|
| 131 |
+
Weights associated with intermediate loop outputs during multi-loop training. When this list is non-empty,
|
| 132 |
+
the model executes `len(loop_loss_weights) + 1` loops instead of using `num_loops`. For the standard loop
|
| 133 |
+
layout, the weights must sum to at most 1.0. Defaults to an empty list.
|
| 134 |
+
skip_loop_final_norm (`bool`, *optional*, defaults to `False`):
|
| 135 |
+
Whether to skip the final RMS normalization between loops. If `True`, normalization is applied only after
|
| 136 |
+
the last loop; if `False`, every loop output is normalized before it is passed to the next loop.
|
| 137 |
+
enable_double_loop_split (`bool`, *optional*, defaults to `False`):
|
| 138 |
+
Whether to enable LoopSplit. LoopSplit keeps the outer decoder layers unlooped and repeatedly executes a
|
| 139 |
+
contiguous middle block, providing different effective depths for different parts of the network. When
|
| 140 |
+
enabled, the execution order is controlled by `loop_middle_layers` rather than `num_loops`.
|
| 141 |
+
loop_middle_layers (`int`, *optional*):
|
| 142 |
+
Number of contiguous middle decoder layers repeatedly executed by LoopSplit. It must be a positive factor
|
| 143 |
+
of `num_hidden_layers`. If omitted while LoopSplit is enabled, it defaults to half of
|
| 144 |
+
`num_hidden_layers`, which therefore must be even.
|
| 145 |
+
loop_share_kv (`bool`, *optional*, defaults to `False`):
|
| 146 |
+
Whether repeated executions of a LoopSplit middle layer reuse the key and value states produced by that
|
| 147 |
+
layer's first execution. Requires `enable_double_loop_split=True`.
|
| 148 |
+
mhc_diff_for_loop (`bool`, *optional*, defaults to `False`):
|
| 149 |
+
Whether each repeated execution of a LoopSplit middle layer uses separate mHC connection modules instead
|
| 150 |
+
of sharing one set across repetitions. Requires both `enable_double_loop_split=True` and `enable_mhc=True`.
|
| 151 |
+
mhc_double_stream_position_for_loop (`str`, *optional*):
|
| 152 |
+
Selects where LoopSplit doubles the configured number of residual streams. Accepted values are `"mid"`,
|
| 153 |
+
which doubles streams in the looped middle block, and `"edge"`, which doubles streams in the unlooped outer
|
| 154 |
+
blocks. Requires `enable_double_loop_split=True`.
|
| 155 |
+
enable_hyper_connection (`bool`, *optional*, defaults to `False`):
|
| 156 |
+
Whether to replace the standard single residual path with multiple residual streams connected around each
|
| 157 |
+
attention and MLP sublayer by learned hyper-connection modules.
|
| 158 |
+
enable_mhc (`bool`, *optional*, defaults to `False`):
|
| 159 |
+
Whether to use manifold-constrained hyper-connections (mHC), which constrain the learned residual-stream
|
| 160 |
+
mixing matrices with Sinkhorn normalization. Requires `enable_hyper_connection=True`.
|
| 161 |
+
enable_h_res_identity (`bool`, *optional*, defaults to `False`):
|
| 162 |
+
Whether the residual-stream mixing matrix includes an explicit identity component. Requires
|
| 163 |
+
`enable_hyper_connection=True`.
|
| 164 |
+
mhc_identity_nohresparam (`bool`, *optional*, defaults to `False`):
|
| 165 |
+
Whether the identity component is used without a separately learned residual mixing parameter. Requires
|
| 166 |
+
both `enable_mhc=True` and `enable_h_res_identity=True`.
|
| 167 |
+
num_residual_streams (`int`, *optional*, defaults to 4):
|
| 168 |
+
Base number of residual streams used by hyper-connections. It must be at least 2 when
|
| 169 |
+
`enable_hyper_connection=True`; LoopSplit may double it in the region selected by
|
| 170 |
+
`mhc_double_stream_position_for_loop`.
|
| 171 |
+
mhc_sinkhorn_iterations (`int`, *optional*, defaults to 20):
|
| 172 |
+
Number of Sinkhorn normalization iterations used to constrain mHC residual-stream mixing matrices. It must
|
| 173 |
+
be at least 1 when `enable_mhc=True`.
|
| 174 |
+
mhc_init_gating_factor (`float`, *optional*, defaults to 0.01):
|
| 175 |
+
Initial scale of the learned mHC gating terms that perturb the identity-like initialization of the
|
| 176 |
+
hyper-connection matrices.
|
| 177 |
+
enable_depth_attention (`bool`, *optional*, defaults to `False`):
|
| 178 |
+
Whether to enable depth attention. At each decoder layer, the current query selects and mixes value states
|
| 179 |
+
from cached anchor depths before normal token-level self-attention is applied.
|
| 180 |
+
depth_attention_stride (`int`, *optional*):
|
| 181 |
+
Layer interval at which key/value states are added as depth-attention anchors. It must be positive and
|
| 182 |
+
defaults to `num_hidden_layers // 2` when depth attention is enabled.
|
| 183 |
+
depth_attention_recent_window (`int`, *optional*, defaults to 0):
|
| 184 |
+
Reserved size of a recent-depth window in addition to anchor depths. The current anchor-only implementation
|
| 185 |
+
requires this value to be 0.
|
| 186 |
+
depth_attention_static_anchor_once (`bool`, *optional*, defaults to `True`):
|
| 187 |
+
Whether depth-attention anchors are collected once and reused across repeated LoopSplit executions. This
|
| 188 |
+
must be `True` when depth attention and LoopSplit are enabled together.
|
| 189 |
```python
|
| 190 |
>>> from transformers import NanbeigeModel, NanbeigeConfig
|
| 191 |
+
>>> # Initializing a Nanbeige style configuration
|
|
|
|
| 192 |
>>> configuration = NanbeigeConfig()
|
| 193 |
+
>>> # Initializing a model from the Nanbeige style configuration
|
|
|
|
| 194 |
>>> model = NanbeigeModel(configuration)
|
|
|
|
| 195 |
>>> # Accessing the model configuration
|
| 196 |
>>> configuration = model.config
|
| 197 |
```"""
|