Download test_model.py from paswans05/Ini-i0.5: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/paswans05/Ini-i0.5/resolve/main/test_model.py
- Command line
-
hf download hf://paswans05/Ini-i0.5/test_model.py
-
curl -L -o test_model.py https://huggingface.co/paswans05/Ini-i0.5/resolve/main/test_model.py
1.31 kB
| import torch | |
| from modeling_ini import IniForCausalLM, IniConfig | |
| def test_model(): | |
| print("1. Loading model from './model_save'...") | |
| try: | |
| model = IniForCausalLM.from_pretrained("./model_save") | |
| print(" Success! Model loaded.") | |
| except Exception as e: | |
| print(f" Error loading model: {e}") | |
| return | |
| print("\n2. Model Stats:") | |
| print(f" Parameters: {model.num_parameters():,}") | |
| print(f" Hidden Size: {model.config.hidden_size}") | |
| print(f" Vocab Size: {model.config.vocab_size}") | |
| print("\n3. Running Inference (Forward Pass)...") | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| print(f" Using device: {device}") | |
| model = model.to(device) | |
| model.eval() | |
| # Create dummy input (batch_size=1, seq_len=5) | |
| input_ids = torch.tensor([[101, 200, 300, 400, 500]]).to(device) | |
| print(f" Input IDs: {input_ids.tolist()}") | |
| with torch.no_grad(): | |
| outputs = model(input_ids) | |
| logits = outputs[0] | |
| print(f" Output Logits Shape: {logits.shape}") | |
| print(" Prediction (Random user, untrained model):") | |
| predicted_ids = torch.argmax(logits, dim=-1) | |
| print(f" Predicted Token IDs: {predicted_ids.tolist()}") | |
| print("\nTest Complete!") | |
| if __name__ == "__main__": | |
| test_model() | |