Instructions to use Machlovi/Safe_Phi4_Full2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Machlovi/Safe_Phi4_Full2 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Machlovi/Safe_Phi4_Full2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use Machlovi/Safe_Phi4_Full2 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Machlovi/Safe_Phi4_Full2 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Machlovi/Safe_Phi4_Full2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Machlovi/Safe_Phi4_Full2 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="Machlovi/Safe_Phi4_Full2", max_seq_length=2048, )
| import torch | |
| import unsloth | |
| from transformers import AutoTokenizer, pipeline | |
| from peft import AutoPeftModelForCausalLM | |
| from unsloth import FastLanguageModel # FastVisionModel for LLMs | |
| MODEL_NAME = "unsloth/Phi-4-unsloth-bnb-4bit" # Base model name (e.g., mistralai/Mistral-7B) | |
| model_id = "Machlovi/Safe_Phi4" # Your LoRA fine-tuned adapter | |
| max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally! | |
| load_in_4bit = True | |
| def load_model(): | |
| """Loads the base model and LoRA adapter using Unsloth.""" | |
| print("Loading base model with Unsloth...") | |
| # Use Unsloth to load model in 4-bit efficiently | |
| model, tokenizer = FastLanguageModel.from_pretrained( | |
| model_name=model_id, | |
| max_seq_length=max_seq_length, | |
| load_in_4bit=load_in_4bit, | |
| ) | |
| print("Creating text generation pipeline...") | |
| text_gen_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer) | |
| return text_gen_pipeline | |
| # Load model globally so it doesn't reload on every request | |
| pipe = load_model() | |
| def infer(prompt: str, max_new_tokens=128): | |
| """Generate text using the Unsloth LoRA-adapted model.""" | |
| return pipe(prompt, max_new_tokens=max_new_tokens)[0]['generated_text'] | |