Download init_model.py from paswans05/Ini-i0.5: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/paswans05/Ini-i0.5/resolve/main/init_model.py
- Command line
-
hf download hf://paswans05/Ini-i0.5/init_model.py
-
curl -L -o init_model.py https://huggingface.co/paswans05/Ini-i0.5/resolve/main/init_model.py
1.13 kB
| import torch | |
| import os | |
| from modeling_ini import IniConfig | |
| from modeling_ini import IniForCausalLM | |
| def main(): | |
| print("Loading configuration...") | |
| config = IniConfig.from_pretrained("./") | |
| print("Initializing model (random weights)...") | |
| # Use float16 for laptop friendliness if available, else float32 | |
| dtype = torch.float16 if torch.cuda.is_available() else torch.float32 | |
| print(f"Using dtype: {dtype}") | |
| model = IniForCausalLM(config) | |
| # Move to appropriate dtype | |
| model = model.to(dtype) | |
| print(f"Model initialized. Parameter count: {model.num_parameters():,}") | |
| # Simple forward pass check | |
| print("Running dummy forward pass...") | |
| input_ids = torch.randint(0, config.vocab_size, (1, 10)) | |
| with torch.no_grad(): | |
| outputs = model(input_ids) | |
| print(f"Output shape: {outputs.logits.shape}") | |
| print("Saving model...") | |
| save_path = "./model_save" | |
| os.makedirs(save_path, exist_ok=True) | |
| model.save_pretrained(save_path) | |
| config.save_pretrained(save_path) | |
| print(f"Model saved to {save_path}") | |
| if __name__ == "__main__": | |
| main() | |