mzbac commited on
Commit
9154f92
1 Parent(s): 40f1288

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +136 -0
README.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - mzbac/function-calling-phi-3-format-v1.1
4
+ ---
5
+
6
+ # Model
7
+
8
+ Fine-tuned the Phi3 instruction model for function calling via MLX-LM using https://huggingface.co/datasets/mzbac/function-calling-phi-3-format-v1.1
9
+
10
+
11
+ # Usage
12
+ ```python
13
+ from transformers import AutoTokenizer, AutoModelForCausalLM
14
+ import torch
15
+
16
+ model_id = "mzbac/Phi-3-mini-4k-instruct-function-calling"
17
+
18
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
19
+ model = AutoModelForCausalLM.from_pretrained(
20
+ model_id,
21
+ torch_dtype=torch.bfloat16,
22
+ device_map="auto",
23
+ attn_implementation="flash_attention_2",
24
+ )
25
+
26
+ tool = {
27
+ "name": "search_web",
28
+ "description": "Perform a web search for a given search terms.",
29
+ "parameter": {
30
+ "type": "object",
31
+ "properties": {
32
+ "search_terms": {
33
+ "type": "array",
34
+ "items": {"type": "string"},
35
+ "description": "The search queries for which the search is performed.",
36
+ "required": True,
37
+ }
38
+ },
39
+ },
40
+ }
41
+
42
+ messages = [
43
+ {
44
+ "role": "user",
45
+ "content": f"You are a helpful assistant with access to the following functions. Use them if required - {str(tool)}",
46
+ },
47
+ {"role": "user", "content": "Any news in Melbourne today, May 7, 2024?"},
48
+ ]
49
+
50
+ input_ids = tokenizer.apply_chat_template(
51
+ messages, add_generation_prompt=True, return_tensors="pt"
52
+ ).to(model.device)
53
+
54
+ terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|end|>")]
55
+
56
+ outputs = model.generate(
57
+ input_ids,
58
+ max_new_tokens=256,
59
+ eos_token_id=terminators,
60
+ do_sample=True,
61
+ temperature=0.1,
62
+ )
63
+ response = outputs[0]
64
+ print(tokenizer.decode(response))
65
+
66
+ # <s><|user|> You are a helpful assistant with access to the following functions. Use them if required - {'name': 'search_web', 'description': 'Perform a web search for a given search terms.', 'parameter': {'type': 'object', 'properties': {'search_terms': {'type': 'array', 'items': {'type': 'string'}, 'description': 'The search queries for which the search is performed.', 'required': True}}}}<|end|><|assistant|>
67
+ # <|user|> Any news in Melbourne today, May 7, 2024?<|end|>
68
+ # <|assistant|> <functioncall> {"name": "search_web", "arguments": {"search_terms": ["news", "Melbourne", "May 7, 2024"]}}<|end|>
69
+ ```
70
+
71
+ # Training hyperparameters
72
+ lora_config.yaml
73
+ ```yaml
74
+ # The path to the local model directory or Hugging Face repo.
75
+ model: "microsoft/Phi-3-mini-4k-instruct"
76
+ # Whether or not to train (boolean)
77
+ train: true
78
+
79
+ # Directory with {train, valid, test}.jsonl files
80
+ data: "data"
81
+
82
+ # The PRNG seed
83
+ seed: 0
84
+
85
+ # Number of layers to fine-tune
86
+ lora_layers: 32
87
+
88
+ # Minibatch size.
89
+ batch_size: 1
90
+
91
+ # Iterations to train for.
92
+ iters: 111000
93
+
94
+ # Number of validation batches, -1 uses the entire validation set.
95
+ val_batches: -1
96
+
97
+ # Adam learning rate.
98
+ learning_rate: 1e-6
99
+
100
+ # Number of training steps between loss reporting.
101
+ steps_per_report: 10
102
+
103
+ # Number of training steps between validations.
104
+ steps_per_eval: 200
105
+
106
+ # Load path to resume training with the given adapter weights.
107
+ # resume_adapter_file: "adapters/adapters.safetensors"
108
+
109
+ # Save/load path for the trained adapter weights.
110
+ adapter_path: "adapters"
111
+
112
+ # Save the model every N iterations.
113
+ save_every: 1000
114
+
115
+ # Evaluate on the test set after training
116
+ test: false
117
+
118
+ # Number of test set batches, -1 uses the entire test set.
119
+ test_batches: 100
120
+
121
+ # Maximum sequence length.
122
+ max_seq_length: 4096
123
+
124
+ # Use gradient checkpointing to reduce memory use.
125
+ grad_checkpoint: false
126
+
127
+ # LoRA parameters can only be specified in a config file
128
+ lora_parameters:
129
+ # The layer keys to apply LoRA to.
130
+ # These will be applied for the last lora_layers
131
+ keys: ['mlp.down_proj','mlp.gate_up_proj','self_attn.qkv_proj','self_attn.o_proj']
132
+ rank: 128
133
+ alpha: 256
134
+ scale: 10.0
135
+ dropout: 0.05
136
+ ```