AdvaithMagic commited on
Commit
8caa5bc
·
verified ·
1 Parent(s): a4f4aef

Export TinyIndianLM checkpoint in HF format

Browse files
config.json CHANGED
@@ -17,6 +17,7 @@
17
  "dropout": 0.0,
18
  "rope_theta": 10000.0,
19
  "pad_token_id": 0,
 
20
  "bos_token_id": 2,
21
  "eos_token_id": 3,
22
  "torch_dtype": "float32",
 
17
  "dropout": 0.0,
18
  "rope_theta": 10000.0,
19
  "pad_token_id": 0,
20
+ "unk_token_id": 1,
21
  "bos_token_id": 2,
22
  "eos_token_id": 3,
23
  "torch_dtype": "float32",
configuration_tinyindianlm.py CHANGED
@@ -16,6 +16,7 @@ class TinyIndianLMConfig(PretrainedConfig):
16
  dropout=0.0,
17
  rope_theta=10000.0,
18
  pad_token_id=0,
 
19
  bos_token_id=2,
20
  eos_token_id=3,
21
  **kwargs,
@@ -31,6 +32,7 @@ class TinyIndianLMConfig(PretrainedConfig):
31
  self.rope_theta = rope_theta
32
  super().__init__(
33
  pad_token_id=pad_token_id,
 
34
  bos_token_id=bos_token_id,
35
  eos_token_id=eos_token_id,
36
  **kwargs,
 
16
  dropout=0.0,
17
  rope_theta=10000.0,
18
  pad_token_id=0,
19
+ unk_token_id=1,
20
  bos_token_id=2,
21
  eos_token_id=3,
22
  **kwargs,
 
32
  self.rope_theta = rope_theta
33
  super().__init__(
34
  pad_token_id=pad_token_id,
35
+ unk_token_id=unk_token_id,
36
  bos_token_id=bos_token_id,
37
  eos_token_id=eos_token_id,
38
  **kwargs,
modeling_tinyindianlm.py CHANGED
@@ -48,6 +48,17 @@ class TinyIndianLMForCausalLM(PreTrainedModel):
48
  **kwargs,
49
  ):
50
  del attention_mask, kwargs
 
 
 
 
 
 
 
 
 
 
 
51
  logits, loss = self.model(
52
  input_ids,
53
  targets=labels,
 
48
  **kwargs,
49
  ):
50
  del attention_mask, kwargs
51
+
52
+ # Safety guard for exported repos where tokenizer vocab and
53
+ # model embedding size diverge. Any out-of-range token id is
54
+ # mapped to unk to avoid embedding lookup crashes.
55
+ if input_ids is not None:
56
+ vocab_size = self.model.embedding.num_embeddings
57
+ if (input_ids >= vocab_size).any():
58
+ unk_id = getattr(self.config, "unk_token_id", 1)
59
+ input_ids = input_ids.clone()
60
+ input_ids[input_ids >= vocab_size] = unk_id
61
+
62
  logits, loss = self.model(
63
  input_ids,
64
  targets=labels,