ykyao commited on
Commit
16e089c
·
verified ·
1 Parent(s): 614ad44

Default to BF16 weights for inference

Browse files
Files changed (3) hide show
  1. README.md +3 -1
  2. config.json +3 -2
  3. modeling_baseline.py +1 -1
README.md CHANGED
@@ -34,7 +34,7 @@ model_id = "osunlp/ARLoop-baseline-0.6B"
34
  device = "cuda" if torch.cuda.is_available() else "cpu"
35
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
36
  model = AutoModelForCausalLM.from_pretrained(
37
- model_id, trust_remote_code=True, dtype=torch.float32,
38
  ).to(device).eval()
39
  inputs = tokenizer("The capital of France is", return_tensors="pt").to(device)
40
  with torch.inference_mode():
@@ -42,6 +42,8 @@ with torch.inference_mode():
42
  print(tokenizer.decode(output[0], skip_special_tokens=True))
43
  ```
44
 
 
 
45
  ## Architecture
46
 
47
  | Property | Value |
 
34
  device = "cuda" if torch.cuda.is_available() else "cpu"
35
  tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
36
  model = AutoModelForCausalLM.from_pretrained(
37
+ model_id, trust_remote_code=True, dtype=torch.bfloat16,
38
  ).to(device).eval()
39
  inputs = tokenizer("The capital of France is", return_tensors="pt").to(device)
40
  with torch.inference_mode():
 
42
  print(tokenizer.decode(output[0], skip_special_tokens=True))
43
  ```
44
 
45
+ Weights load in BF16 for inference. The stored checkpoint retains the original FP32 weights; normalization statistics use FP32 internally.
46
+
47
  ## Architecture
48
 
49
  | Property | Value |
config.json CHANGED
@@ -7,7 +7,7 @@
7
  "AutoModelForCausalLM": "modeling_baseline.ARLoopBaselineForCausalLM"
8
  },
9
  "bos_token_id": 0,
10
- "dtype": "float32",
11
  "embedding_scale": 1.0,
12
  "eos_token_id": 0,
13
  "head_dim": 96,
@@ -29,5 +29,6 @@
29
  "tie_word_embeddings": true,
30
  "transformers_version": "5.12.1",
31
  "use_cache": true,
32
- "vocab_size": 49152
 
33
  }
 
7
  "AutoModelForCausalLM": "modeling_baseline.ARLoopBaselineForCausalLM"
8
  },
9
  "bos_token_id": 0,
10
+ "dtype": "bfloat16",
11
  "embedding_scale": 1.0,
12
  "eos_token_id": 0,
13
  "head_dim": 96,
 
29
  "tie_word_embeddings": true,
30
  "transformers_version": "5.12.1",
31
  "use_cache": true,
32
+ "vocab_size": 49152,
33
+ "torch_dtype": "bfloat16"
34
  }
modeling_baseline.py CHANGED
@@ -158,7 +158,7 @@ class ARLoopBaselineForCausalLM(PreTrainedModel, GenerationMixin):
158
  if not bool(attention_mask.all()):
159
  mask = (key_indices[None, :] <= query_indices[:, None])[None, None, :, :]
160
  mask = mask & attention_mask[:, None, None, :].bool()
161
- # FP32 residual/value embeddings with BF16 autocast, as in training.
162
  with torch.autocast(device_type=input_ids.device.type, dtype=torch.bfloat16):
163
  h = self.transformer.wte(input_ids) * self.config.embedding_scale
164
  ve = self.shared_value_embedding(input_ids)
 
158
  if not bool(attention_mask.all()):
159
  mask = (key_indices[None, :] <= query_indices[:, None])[None, None, :, :]
160
  mask = mask & attention_mask[:, None, None, :].bool()
161
+ # Residual/value embeddings follow the loading dtype; Linear ops use BF16 autocast.
162
  with torch.autocast(device_type=input_ids.device.type, dtype=torch.bfloat16):
163
  h = self.transformer.wte(input_ids) * self.config.embedding_scale
164
  ve = self.shared_value_embedding(input_ids)