Priyanka6 commited on
Commit
006aba1
Β·
1 Parent(s): 3c6c542

Update space

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -75,6 +75,29 @@ MODEL_2_NAME = "sarvamai/sarvam-1" # The base model on Hugging Face Hub
75
  # Load the tokenizer (same for both models)
76
  TOKENIZER_NAME = "sarvamai/sarvam-1"
77
  tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  # Function to load a model
80
  def load_model(model_choice):
 
75
  # Load the tokenizer (same for both models)
76
  TOKENIZER_NAME = "sarvamai/sarvam-1"
77
  tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
78
+ def fix_checkpoint(model_path):
79
+ """Fixes the model checkpoint by adjusting mismatched weight dimensions."""
80
+ checkpoint_file = os.path.join(model_path, "pytorch_model.bin")
81
+ fixed_checkpoint_file = os.path.join(model_path, "pytorch_model_fixed.bin")
82
+
83
+ if not os.path.exists(checkpoint_file):
84
+ raise FileNotFoundError(f"Checkpoint file not found at: {checkpoint_file}")
85
+
86
+ print("Loading checkpoint for fixing...")
87
+ checkpoint = torch.load(checkpoint_file, map_location="cpu")
88
+
89
+ # Adjust weights (truncate the last token if mismatch)
90
+ if "base_model.model.lm_head.base_layer.weight" in checkpoint:
91
+ checkpoint["base_model.model.lm_head.base_layer.weight"] = checkpoint["base_model.model.lm_head.base_layer.weight"][:-1]
92
+
93
+ if "base_model.model.lm_head.lora_B.default.weight" in checkpoint:
94
+ checkpoint["base_model.model.lm_head.lora_B.default.weight"] = checkpoint["base_model.model.lm_head.lora_B.default.weight"][:-1]
95
+
96
+ # Save the fixed checkpoint
97
+ print("Saving fixed checkpoint...")
98
+ torch.save(checkpoint, fixed_checkpoint_file)
99
+
100
+ return fixed_checkpoint_file # Return the new file path
101
 
102
  # Function to load a model
103
  def load_model(model_choice):