|
|
--- |
|
|
license: apache-2.0 |
|
|
library_name: transformers |
|
|
--- |
|
|
To load this model from the Hugging Face Hub in Python: |
|
|
```python |
|
|
# 0. If in Colab and it's a new session, or if model is private, authenticate: |
|
|
# from huggingface_hub import notebook_login; notebook_login() |
|
|
|
|
|
# 1. Import necessary libraries: |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
# The following torch imports might be needed if you were to define the classes manually, |
|
|
# but trust_remote_code=True should handle it by loading them from the Hub. |
|
|
# import torch |
|
|
# import torch.nn as nn |
|
|
|
|
|
# 2. Define your model ID: |
|
|
MODEL_ID = "moelanoby/Sensitive-Qwen-0.5B" |
|
|
|
|
|
# 3. Load tokenizer and model (trust_remote_code=True is CRUCIAL): |
|
|
# This allows Transformers to download and use the Python file ('LLMadd.py') |
|
|
# from your Hub repository, which contains the definitions for |
|
|
# `SensitivityModule` and `SensitiveBottleneckLayer`. |
|
|
|
|
|
try: |
|
|
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True) |
|
|
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, trust_remote_code=True, device_map='auto') # Add other params as needed |
|
|
print(f'Model {MODEL_ID} loaded successfully!') |
|
|
except Exception as e: |
|
|
print(f'Error loading model: {e}') |
|
|
print('Ensure the custom code file (LLMadd.py) in the Hub repo is correct and classes are defined.') |
|
|
|
|
|
# 4. Example generation (adjust based on your model's chat template, e.g., Qwen2-Instruct): |
|
|
# prompt = "What is the capital of France?" |
|
|
# messages = [{"role": "user", "content": prompt}] |
|
|
# text_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) |
|
|
# model_inputs = tokenizer([text_input], return_tensors="pt").to(model.device) |
|
|
# generated_ids = model.generate(model_inputs.input_ids, max_new_tokens=50) |
|
|
# result = tokenizer.batch_decode(generated_ids[:, model_inputs.input_ids.shape[-1]:], skip_special_tokens=True)[0] |
|
|
# print(f'Generated: {result}') |
|
|
``` |
|
|
|
|
|
IMPORTANT: `trust_remote_code=True` allows the execution of Python code |
|
|
from the 'moelanoby/Sensitive-Qwen-0.5B' repository on Hugging Face Hub. |