File size: 2,538 Bytes
f2b7f6a
c28cb48
 
 
 
 
 
 
 
 
 
 
 
 
f2b7f6a
 
c28cb48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
language:
- en
license: mit
base_model: microsoft/Phi-3-mini-4k-instruct
tags:
- phi-3
- lora
- spiritual
- ramana-maharshi
- advaita-vedanta
- self-enquiry
- rag
pipeline_tag: text-generation
---

# Ramana Maharshi Teaching Assistant — Phi-3 Mini LoRA

A LoRA fine-tuned version of [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct)
trained on verified teachings of Sri Ramana Maharshi.

## Training

- **Base model**: `microsoft/Phi-3-mini-4k-instruct`
- **Method**: QLoRA (4-bit NF4) + SFT → DPO
- **SFT data**: Single-turn and multi-turn Q&A grounded in canonical texts
- **DPO data**: Preference pairs (verified teachings vs. generic responses)
- **Canonical sources**: *Who Am I?*, *Talks with Sri Ramana Maharshi*, *Ulladu Narpadu*
- **LoRA rank**: 16 | Alpha: 32 | Target: all attention + MLP projection layers

## Usage

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id  = "SriRamanaAtmic/AtmicIntel_test"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model     = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype       = torch.bfloat16,
    device_map        = "auto",
    trust_remote_code = True,
)

SYSTEM = (
    "You are a knowledgeable and compassionate guide to the teachings of "
    "Sri Ramana Maharshi. Answer questions about Self-enquiry, the nature "
    "of the Self, surrender, and the path to liberation, grounded in his "
    "actual teachings."
)

messages = [
    {"role": "system",    "content": SYSTEM},
    {"role": "user",      "content": "What is self-enquiry?"},
]
text   = tokenizer.apply_chat_template(messages, tokenize=False,
                                        add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

with torch.no_grad():
    out = model.generate(
        **inputs,
        max_new_tokens     = 512,
        temperature        = 0.7,
        top_p              = 0.9,
        repetition_penalty = 1.1,
        do_sample          = True,
    )
print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
```

## About Sri Ramana Maharshi

Sri Ramana Maharshi (1879–1950) was one of the greatest sages of modern India.
His principal teaching was *Atma Vichara* (Self-enquiry): the direct path of
tracing the sense of "I" back to its source, the Self — pure, undivided
awareness. He is revered across traditions for the simplicity, depth, and
transformative power of his teachings.