Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "Prithvi-Aithal/phi3-mini-os-finetuned"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.float16,
10 device_map="auto"
11)
12
13def ask_os(question):
14 prompt = f"<|user|>\n{question}<|end|>\n<|assistant|>\n"
15 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
16
17 with torch.no_grad():
18 outputs = model.generate(
19 **inputs,
20 max_new_tokens=300,
21 temperature=0.7,
22 do_sample=True,
23 pad_token_id=tokenizer.eos_token_id
24 )
25
26 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
27 return response.split("<|assistant|>")[-1].strip()
28
29# Example
30print(ask_os("What is the difference between a process and a thread?"))
31print(ask_os("Explain Banker's Algorithm for deadlock avoidance."))
32print(ask_os("What are the conditions for a deadlock to occur?"))A process is an independent program in execution with its own memory space, file handles, and system resources. A thread is a lightweight unit of execution within a process — multiple threads share the same memory space and resources but have their own stack and program counter. Threads are faster to create and context-switch than processes.
The four necessary conditions for deadlock (Coffman conditions) are: (1) Mutual Exclusion — at least one resource must be held in a non-shareable mode; (2) Hold and Wait — a process holds at least one resource while waiting to acquire additional resources; (3) No Preemption — resources cannot be forcibly taken from a process; (4) Circular Wait — a set of processes exist such that each is waiting for a resource held by the next process in the cycle.
| Parameter | Value |
|---|---|
| Base Model | Phi-3 Mini 4K Instruct |
| Quantization | 4-bit (NF4) via bitsandbytes |
| LoRA Rank (r) | 16 |
| LoRA Alpha | 32 |
| LoRA Dropout | 0.05 |
| Target Modules | q_proj, v_proj |
| Training Examples | 200 |
| Epochs | 3 |
| Batch Size | 4 (with gradient accumulation) |
| Learning Rate | 2e-4 |
| Optimizer | paged_adamw_32bit |
| Hardware | Google Colab (T4 GPU) |