Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
To load this model from the Hugging Face Hub in Python:
|
| 2 |
+
```python
|
| 3 |
+
# 0. If in Colab and it's a new session, or if model is private, authenticate:
|
| 4 |
+
# from huggingface_hub import notebook_login; notebook_login()
|
| 5 |
+
|
| 6 |
+
# 1. Import necessary libraries:
|
| 7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
+
# The following torch imports might be needed if you were to define the classes manually,
|
| 9 |
+
# but trust_remote_code=True should handle it by loading them from the Hub.
|
| 10 |
+
# import torch
|
| 11 |
+
# import torch.nn as nn
|
| 12 |
+
|
| 13 |
+
# 2. Define your model ID:
|
| 14 |
+
MODEL_ID = "moelanoby/Sensitive-Qwen-0.5B"
|
| 15 |
+
|
| 16 |
+
# 3. Load tokenizer and model (trust_remote_code=True is CRUCIAL):
|
| 17 |
+
# This allows Transformers to download and use the Python file ('LLMadd.py')
|
| 18 |
+
# from your Hub repository, which contains the definitions for
|
| 19 |
+
# `SensitivityModule` and `SensitiveBottleneckLayer`.
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, trust_remote_code=True, device_map='auto') # Add other params as needed
|
| 24 |
+
print(f'Model {MODEL_ID} loaded successfully!')
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f'Error loading model: {e}')
|
| 27 |
+
print('Ensure the custom code file (LLMadd.py) in the Hub repo is correct and classes are defined.')
|
| 28 |
+
|
| 29 |
+
# 4. Example generation (adjust based on your model's chat template, e.g., Qwen2-Instruct):
|
| 30 |
+
# prompt = "What is the capital of France?"
|
| 31 |
+
# messages = [{"role": "user", "content": prompt}]
|
| 32 |
+
# text_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 33 |
+
# model_inputs = tokenizer([text_input], return_tensors="pt").to(model.device)
|
| 34 |
+
# generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=50)
|
| 35 |
+
# result = tokenizer.batch_decode(generated_ids[:, model_inputs.input_ids.shape[-1]:], skip_special_tokens=True)[0]
|
| 36 |
+
# print(f'Generated: {result}')
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
IMPORTANT: `trust_remote_code=True` allows the execution of Python code
|
| 40 |
+
from the 'moelanoby/Sensitive-Qwen-0.5B' repository on Hugging Face Hub.
|