MrunangG commited on
Commit
b456c1a
·
verified ·
1 Parent(s): 6440419

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +89 -40
README.md CHANGED
@@ -1,62 +1,111 @@
1
  ---
 
 
2
  base_model: microsoft/phi-2
3
- library_name: peft
4
- model_name: results
5
  tags:
6
- - base_model:adapter:microsoft/phi-2
 
 
 
 
7
  - lora
8
- - sft
9
- - transformers
10
- - trl
11
- licence: license
12
- pipeline_tag: text-generation
13
  ---
14
 
15
- # Model Card for results
16
 
17
- This model is a fine-tuned version of [microsoft/phi-2](https://huggingface.co/microsoft/phi-2).
18
- It has been trained using [TRL](https://github.com/huggingface/trl).
19
 
20
- ## Quick start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  ```python
23
- from transformers import pipeline
 
 
24
 
25
- question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
26
- generator = pipeline("text-generation", model="None", device="cuda")
27
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
28
- print(output["generated_text"])
29
- ```
30
 
31
- ## Training procedure
 
32
 
33
-
 
 
 
 
 
 
34
 
 
 
 
 
35
 
36
- This model was trained with SFT.
 
37
 
38
- ### Framework versions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
 
 
 
 
40
  - PEFT 0.17.1
41
  - TRL: 0.22.1
42
  - Transformers: 4.56.0
43
  - Pytorch: 2.8.0
44
  - Datasets: 4.0.0
45
- - Tokenizers: 0.22.0
46
-
47
- ## Citations
48
-
49
-
50
-
51
- Cite TRL as:
52
-
53
- ```bibtex
54
- @misc{vonwerra2022trl,
55
- title = {{TRL: Transformer Reinforcement Learning}},
56
- author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
57
- year = 2020,
58
- journal = {GitHub repository},
59
- publisher = {GitHub},
60
- howpublished = {\url{https://github.com/huggingface/trl}}
61
- }
62
- ```
 
1
  ---
2
+ license: mit
3
+ language: en
4
  base_model: microsoft/phi-2
 
 
5
  tags:
6
+ - text-generation
7
+ - voice-assistant
8
+ - automotive
9
+ - fine-tuned
10
+ - peft
11
  - lora
12
+ datasets:
13
+ - synthetic
14
+ widget:
15
+ - text: "Navigate to the nearest EV charging station."
16
+ - text: "Set the temperature to 22 degrees."
17
  ---
18
 
19
+ # 🚗 Fine-tuned MBUX Voice Assistant (phi-2)
20
 
21
+ This repository contains a fine-tuned version of Microsoft's **`microsoft/phi-2`** model, specifically adapted to function as an in-car voice assistant similar to MBUX. The model is trained to understand and respond to common automotive commands.
 
22
 
23
+ This model was created as part of an end-to-end MLOps project, from data creation and fine-tuning to deployment in an interactive application.
24
+
25
+ ## ✨ Live Demo
26
+
27
+ You can interact with this model in a live, voice-to-voice application on Hugging Face Spaces:
28
+
29
+ **➡️ [Live MBUX Gradio Demo](https://huggingface.co/spaces/MrunangG/mbux-gradio-demo)**
30
+
31
+
32
+
33
+ ---
34
+
35
+ ## 📝 Model Details
36
+
37
+ * **Base Model:** `microsoft/phi-2`
38
+ * **Fine-tuning Method:** Parameter-Efficient Fine-Tuning (PEFT) using LoRA.
39
+ * **Training Data:** A synthetic, instruction-based dataset of in-car commands covering navigation, climate control, media, and vehicle settings.
40
+ * **Frameworks:** PyTorch, Transformers, PEFT, TRL.
41
+
42
+ ### Intended Use
43
+
44
+ This model is a proof-of-concept designed for demonstration purposes. It's intended to be used as the "brain" for a voice assistant application in an automotive context. It excels at understanding commands like:
45
+ * "Navigate to the office."
46
+ * "Set the fan speed to maximum."
47
+ * "Play my 'Morning Commute' playlist."
48
+
49
+ ---
50
+
51
+ ## 🚀 How to Use
52
+
53
+ This is a PEFT model (LoRA adapter), so you must load it on top of the base `microsoft/phi-2` model. The following code snippet shows the correct way to do this.
54
 
55
  ```python
56
+ import torch
57
+ from peft import PeftModel
58
+ from transformers import AutoModelForCausalLM, AutoTokenizer
59
 
60
+ # Define the model repository IDs
61
+ base_model_id = "microsoft/phi-2"
62
+ peft_model_id = "MrunangG/phi-2-mbux-assistant"
 
 
63
 
64
+ # Set device
65
+ device = "cuda" if torch.cuda.is_available() else "cpu"
66
 
67
+ # Load the base model
68
+ base_model = AutoModelForCausalLM.from_pretrained(
69
+ base_model_id,
70
+ trust_remote_code=True,
71
+ torch_dtype=torch.float16,
72
+ device_map={"": device}
73
+ )
74
 
75
+ # Load the tokenizer
76
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
77
+ if tokenizer.pad_token is None:
78
+ tokenizer.pad_token = tokenizer.eos_token
79
 
80
+ # Load the PEFT model by merging the adapter
81
+ model = PeftModel.from_pretrained(base_model, peft_model_id)
82
 
83
+ # --- Inference ---
84
+ prompt = "Set the temperature to 21 degrees."
85
+ formatted_prompt = f"[INST] {prompt} [/INST]"
86
+
87
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to(device)
88
+
89
+ with torch.no_grad():
90
+ outputs = model.generate(**inputs, max_new_tokens=50)
91
+
92
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
93
+ cleaned_response = response.split('[/INST]')[-1].strip()
94
+
95
+ print(cleaned_response)
96
+ # Expected output: Okay, setting the cabin temperature to 21 degrees.
97
+ ```
98
+
99
+ ---
100
 
101
+ ## 🛠️ Training Procedure
102
+
103
+ The model was fine-tuned using the `SFTTrainer` from the TRL library. Key training parameters included a learning rate of `2e-4`, the `paged_adamw_8bit` optimizer, and 4-bit quantization to ensure efficient training on consumer hardware.
104
+
105
+ ### Framework versions
106
  - PEFT 0.17.1
107
  - TRL: 0.22.1
108
  - Transformers: 4.56.0
109
  - Pytorch: 2.8.0
110
  - Datasets: 4.0.0
111
+ - Tokenizers: 0.22.0