annekethvij commited on
Commit
e2ef4a3
·
verified ·
1 Parent(s): b576b32

Document inference precision and preserve FP32 expert biases

Browse files
Files changed (2) hide show
  1. README.md +6 -23
  2. modeling_afmoe.py +1 -0
README.md CHANGED
@@ -72,17 +72,12 @@ More details, including key architecture decisions, can be found on our blog [he
72
 
73
  ## Transformers
74
 
75
- Use the `main` transformers branch
76
 
77
- ```
78
- git clone https://github.com/huggingface/transformers.git
79
- cd transformers
80
-
81
- # pip
82
- pip install '.[torch]'
83
 
84
- # uv
85
- uv pip install '.[torch]'
86
  ```
87
 
88
  ```python
@@ -94,7 +89,8 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
94
  model = AutoModelForCausalLM.from_pretrained(
95
  model_id,
96
  torch_dtype=torch.bfloat16,
97
- device_map="auto"
 
98
  )
99
 
100
  messages = [
@@ -120,19 +116,6 @@ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
120
  print(response)
121
  ```
122
 
123
- If using a released transformers, simply pass "trust_remote_code=True":
124
-
125
- ```python
126
- model_id = "arcee-ai/Trinity-Nano-Preview"
127
- tokenizer = AutoTokenizer.from_pretrained(model_id)
128
- model = AutoModelForCausalLM.from_pretrained(
129
- model_id,
130
- torch_dtype=torch.bfloat16,
131
- device_map="auto",
132
- trust_remote_code=True
133
- )
134
- ```
135
-
136
  ## VLLM
137
 
138
  Supported in VLLM release 0.11.1
 
72
 
73
  ## Transformers
74
 
75
+ **Inference precision:** For unquantized BF16 inference, the intended parameter dtypes are BF16 for normalization and router weights, and FP32 for expert correction biases (`expert_bias`). Preserve FP32 checkpoint bias values during loading.
76
 
77
+ Use the bundled model implementation with `transformers==4.57.1` and `trust_remote_code=True`.
 
 
 
 
 
78
 
79
+ ```bash
80
+ pip install "transformers==4.57.1" "accelerate==1.11.0"
81
  ```
82
 
83
  ```python
 
89
  model = AutoModelForCausalLM.from_pretrained(
90
  model_id,
91
  torch_dtype=torch.bfloat16,
92
+ device_map="auto",
93
+ trust_remote_code=True
94
  )
95
 
96
  messages = [
 
116
  print(response)
117
  ```
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  ## VLLM
120
 
121
  Supported in VLLM release 0.11.1
modeling_afmoe.py CHANGED
@@ -469,6 +469,7 @@ class AfmoeDecoderLayer(GradientCheckpointingLayer):
469
 
470
 
471
  class AfmoePreTrainedModel(PreTrainedModel):
 
472
  config_class = AfmoeConfig
473
  base_model_prefix = "model"
474
  _no_split_modules = ["AfmoeDecoderLayer"]
 
469
 
470
 
471
  class AfmoePreTrainedModel(PreTrainedModel):
472
+ _keep_in_fp32_modules_strict = ["expert_bias"]
473
  config_class = AfmoeConfig
474
  base_model_prefix = "model"
475
  _no_split_modules = ["AfmoeDecoderLayer"]