Skip to content

Commit 3630908

Browse files
committed
Add Phi4
1 parent 1a43259 commit 3630908

7 files changed

+66
-52
lines changed

recipes/configs/phi3/evaluation.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@ output_dir: ./ # Not needed
77

88
# Model Arguments
99
model:
10-
_component_: torchtune.models.phi3.phi3_mini
10+
_component_: torchtune.models.phi4.phi4_mini
1111

1212
# Checkpointer
1313
checkpointer:
1414
_component_: torchtune.training.FullModelHFCheckpointer
15-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
15+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
1616
checkpoint_files: [
1717
model-00001-of-00002.safetensors,
1818
model-00002-of-00002.safetensors
1919
]
2020
recipe_checkpoint: null
2121
output_dir: ${output_dir}
22-
model_type: PHI3_MINI
22+
model_type: PHI4_MINI
2323
resume_from_checkpoint: False
2424

2525
# Tokenizer
2626
tokenizer:
27-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
28-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
27+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
28+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
2929
max_seq_len: null
3030

3131
# Environment

recipes/configs/phi4/mini_full.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@
33
#
44
# This config assumes that you've run the following command before launching
55
# this run:
6-
# tune download microsoft/Phi-3-mini-4k-instruct --output-dir /tmp/Phi-3-mini-4k-instruct --hf-token <HF_TOKEN>
6+
# tune download microsoft/Phi-4-mini-16k-instruct --output-dir /tmp/Phi-4-mini-16k-instruct --hf-token <HF_TOKEN>
77
#
88
# Run this config on 4 GPUs using the following:
9-
# tune run --nproc_per_node 4 full_finetune_distributed --config phi3/mini_full
9+
# tune run --nproc_per_node 4 full_finetune_distributed --config phi4/mini_full
1010
#
1111
# You can add specific overrides through the command line. For example
1212
# to override the checkpointer directory while launching training
1313
# you can run:
14-
# tune run --nproc_per_node 4 full_finetune_distributed --config phi3/mini_full checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
14+
# tune run --nproc_per_node 4 full_finetune_distributed --config phi4/mini_full checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
1515
#
1616
# This config works best when the model is being fine-tuned on 2+ GPUs.
1717
# Single device full finetuning requires more memory optimizations. It's
1818
# best to use mini_low_memory.yaml for those cases
1919

20-
output_dir: /tmp/torchtune/phi3_mini/full # /tmp may be deleted by your system. Change it to your preference.
20+
output_dir: /tmp/torchtune/phi4_mini/full # /tmp may be deleted by your system. Change it to your preference.
2121

2222
# Model arguments
2323
model:
24-
_component_: torchtune.models.phi3.phi3_mini
24+
_component_: torchtune.models.phi4.phi4_mini
2525

2626
# Tokenizer
2727
tokenizer:
28-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
29-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
28+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
29+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
3030
max_seq_len: null
3131

3232
# Checkpointer
3333
checkpointer:
3434
_component_: torchtune.training.FullModelHFCheckpointer
35-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
35+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
3636
checkpoint_files: [
3737
model-00001-of-00002.safetensors,
3838
model-00002-of-00002.safetensors
3939
]
4040
recipe_checkpoint: null
4141
output_dir: ${output_dir}
42-
model_type: PHI3_MINI
42+
model_type: PHI4_MINI
4343
resume_from_checkpoint: False
4444

4545
# Dataset

recipes/configs/phi4/mini_full_low_memory.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,45 @@
33
#
44
# This config assumes that you've run the following command before launching
55
# this run:
6-
# tune download microsoft/Phi-3-mini-4k-instruct --output-dir /tmp/Phi-3-mini-4k-instruct --hf-token <HF_TOKEN>
6+
# tune download microsoft/Phi-4-mini-16k-instruct --output-dir /tmp/Phi-4-mini-16k-instruct --hf-token <HF_TOKEN>
77
#
88
# The default config uses an optimizer from bitsandbytes. If you do not have it installed,
99
# you can install it with
1010
# pip install bitsandbytes
1111
#
1212
# To launch on a single device, run the following command from root:
13-
# tune run full_finetune_single_device --config phi3/mini_full_low_memory
13+
# tune run full_finetune_single_device --config phi4/mini_full_low_memory
1414
#
1515
# You can add specific overrides through the command line. For example
1616
# to override the checkpointer directory while launching training
1717
# you can run:
18-
# tune run full_finetune_single_device --config phi3/mini_full_low_memory checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
18+
# tune run full_finetune_single_device --config phi4/mini_full_low_memory checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
1919
#
2020
# This config works only for training on single device.
2121

22-
output_dir: /tmp/torchtune/phi3_mini/full_low_memory # /tmp may be deleted by your system. Change it to your preference.
22+
output_dir: /tmp/torchtune/phi4_mini/full_low_memory # /tmp may be deleted by your system. Change it to your preference.
2323

2424
# Model arguments
2525
model:
26-
_component_: torchtune.models.phi3.phi3_mini
26+
_component_: torchtune.models.phi4.phi4_mini
2727

2828
# Tokenizer
2929
tokenizer:
30-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
31-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
30+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
31+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
3232
max_seq_len: null
3333

3434
# Checkpointer
3535
checkpointer:
3636
_component_: torchtune.training.FullModelHFCheckpointer
37-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
37+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
3838
checkpoint_files: [
3939
model-00001-of-00002.safetensors,
4040
model-00002-of-00002.safetensors
4141
]
4242
recipe_checkpoint: null
4343
output_dir: ${output_dir}
44-
model_type: PHI3_MINI
44+
model_type: PHI4_MINI
4545
resume_from_checkpoint: False
4646

4747
# Dataset

recipes/configs/phi4/mini_lora.yaml

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
#
44
# This config assumes that you've run the following command before launching
55
# this run:
6-
# tune download microsoft/Phi-3-mini-4k-instruct --output-dir /tmp/Phi-3-mini-4k-instruct --hf-token <HF_TOKEN>
6+
# tune download microsoft/Phi-4-mini-16k-instruct --output-dir /tmp/Phi-4-mini-16k-instruct --hf-token <HF_TOKEN>
77
#
88
# To launch on 2 devices, run the following command from root:
9-
# tune run --nnodes 1 --nproc_per_node 2 lora_finetune_distributed --config phi3/mini_lora
9+
# tune run --nnodes 1 --nproc_per_node 2 lora_finetune_distributed --config phi4/mini_lora
1010
#
1111
# You can add specific overrides through the command line. For example
1212
# to override the checkpointer directory while launching training
1313
# you can run:
14-
# tune run --nnodes 1 --nproc_per_node 2 lora_finetune_distributed --config phi3/mini_lora checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
14+
# tune run --nnodes 1 --nproc_per_node 2 lora_finetune_distributed --config phi4/mini_lora checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
1515
#
1616
# This config works best when the model is being fine-tuned on 2+ GPUs.
1717
# For single device LoRA finetuning please use mini_lora_single_device.yaml
1818
# or mini_qlora_single_device.yaml
1919

20-
output_dir: /tmp/torchtune/phi3_mini/lora # /tmp may be deleted by your system. Change it to your preference.
20+
output_dir: /tmp/torchtune/phi4_mini/lora # /tmp may be deleted by your system. Change it to your preference.
2121

2222
# Model arguments
2323
model:
24-
_component_: torchtune.models.phi3.lora_phi3_mini
24+
_component_: torchtune.models.phi4.lora_phi4_mini
2525
lora_attn_modules: ['q_proj', 'v_proj', 'output_proj']
2626
apply_lora_to_mlp: True
2727
apply_lora_to_output: False
@@ -31,21 +31,21 @@ model:
3131

3232
# Tokenizer
3333
tokenizer:
34-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
35-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
34+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
35+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
3636
max_seq_len: null
3737

3838
# Checkpointer
3939
checkpointer:
4040
_component_: torchtune.training.FullModelHFCheckpointer
41-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
41+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
4242
checkpoint_files: [
4343
model-00001-of-00002.safetensors,
4444
model-00002-of-00002.safetensors
4545
]
4646
recipe_checkpoint: null
4747
output_dir: ${output_dir}
48-
model_type: PHI3_MINI
48+
model_type: PHI4_MINI
4949
resume_from_checkpoint: False
5050
save_adapter_weights_only: False
5151

recipes/configs/phi4/mini_lora_single_device.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
#
44
# This config assumes that you've run the following command before launching
55
# this run:
6-
# tune download microsoft/Phi-3-mini-4k-instruct --output-dir /tmp/Phi-3-mini-4k-instruct --hf-token <HF_TOKEN>
6+
# tune download microsoft/Phi-4-mini-16k-instruct --output-dir /tmp/Phi-4-mini-16k-instruct --hf-token <HF_TOKEN>
77
#
88
# To launch on a single device, run the following command from root:
9-
# tune run lora_finetune_single_device --config phi3/mini_lora_single_device
9+
# tune run lora_finetune_single_device --config phi4/mini_lora_single_device
1010
#
1111
# You can add specific overrides through the command line. For example
1212
# to override the checkpointer directory while launching training
1313
# you can run:
14-
# tune run lora_finetune_single_device --config phi3/mini_lora_single_device checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
14+
# tune run lora_finetune_single_device --config phi4/mini_lora_single_device checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
1515
#
1616
# This config works only for training on single device.
1717

18-
output_dir: /tmp/torchtune/phi3_mini/lora_single_device # /tmp may be deleted by your system. Change it to your preference.
18+
output_dir: /tmp/torchtune/phi4_mini/lora_single_device # /tmp may be deleted by your system. Change it to your preference.
1919

2020
# Model arguments
2121
model:
22-
_component_: torchtune.models.phi3.lora_phi3_mini
22+
_component_: torchtune.models.phi4.lora_phi4_mini
2323
lora_attn_modules: ['q_proj', 'v_proj', 'output_proj']
2424
apply_lora_to_mlp: True
2525
apply_lora_to_output: False
@@ -29,21 +29,21 @@ model:
2929

3030
# Tokenizer
3131
tokenizer:
32-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
33-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
32+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
33+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
3434
max_seq_len: null
3535

3636
# Checkpointer
3737
checkpointer:
3838
_component_: torchtune.training.FullModelHFCheckpointer
39-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
39+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
4040
checkpoint_files: [
4141
model-00001-of-00002.safetensors,
4242
model-00002-of-00002.safetensors
4343
]
4444
recipe_checkpoint: null
4545
output_dir: ${output_dir}
46-
model_type: PHI3_MINI
46+
model_type: PHI4_MINI
4747
resume_from_checkpoint: False
4848
save_adapter_weights_only: False
4949

@@ -95,7 +95,7 @@ profiler:
9595
enabled: False
9696

9797
#Output directory of trace artifacts
98-
output_dir: /tmp/Phi-3-mini-4k-instruct/profiling_outputs
98+
output_dir: /tmp/Phi-4-mini-16k-instruct/profiling_outputs
9999

100100
#`torch.profiler.ProfilerActivity` types to trace
101101
cpu: True

recipes/configs/phi4/mini_qlora_single_device.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
#
44
# This config assumes that you've run the following command before launching
55
# this run:
6-
# tune download microsoft/Phi-3-mini-4k-instruct --output-dir /tmp/Phi-3-mini-4k-instruct --hf-token <HF_TOKEN>
6+
# tune download microsoft/Phi-4-mini-16k-instruct --output-dir /tmp/Phi-4-mini-16k-instruct --hf-token <HF_TOKEN>
77
#
88
# To launch on a single device, run the following command from root:
9-
# tune run lora_finetune_single_device --config phi3/mini_qlora_single_device
9+
# tune run lora_finetune_single_device --config phi4/mini_qlora_single_device
1010
#
1111
# You can add specific overrides through the command line. For example
1212
# to override the checkpointer directory while launching training
1313
# you can run:
14-
# tune run lora_finetune_single_device --config phi3/mini_qlora_single_device checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
14+
# tune run lora_finetune_single_device --config phi4/mini_qlora_single_device checkpointer.checkpoint_dir=<YOUR_CHECKPOINT_DIR>
1515
#
1616
# This config works only for training on single device.
1717

18-
output_dir: /tmp/torchtune/phi3_mini/qlora_single_device # /tmp may be deleted by your system. Change it to your preference.
18+
output_dir: /tmp/torchtune/phi4_mini/qlora_single_device # /tmp may be deleted by your system. Change it to your preference.
1919

2020
# Model arguments
2121
model:
22-
_component_: torchtune.models.phi3.qlora_phi3_mini
22+
_component_: torchtune.models.phi4.qlora_phi4_mini
2323
lora_attn_modules: ['q_proj', 'v_proj', 'output_proj']
2424
apply_lora_to_mlp: True
2525
apply_lora_to_output: False
@@ -29,21 +29,21 @@ model:
2929

3030
# Tokenizer
3131
tokenizer:
32-
_component_: torchtune.models.phi3.phi3_mini_tokenizer
33-
path: /tmp/Phi-3-mini-4k-instruct/tokenizer.model
32+
_component_: torchtune.models.phi4.phi4_mini_tokenizer
33+
path: /tmp/Phi-4-mini-16k-instruct/tokenizer.model
3434
max_seq_len: null
3535

3636
# Checkpointer
3737
checkpointer:
3838
_component_: torchtune.training.FullModelHFCheckpointer
39-
checkpoint_dir: /tmp/Phi-3-mini-4k-instruct
39+
checkpoint_dir: /tmp/Phi-4-mini-16k-instruct
4040
checkpoint_files: [
4141
model-00001-of-00002.safetensors,
4242
model-00002-of-00002.safetensors
4343
]
4444
recipe_checkpoint: null
4545
output_dir: ${output_dir}
46-
model_type: PHI3_MINI
46+
model_type: PHI4_MINI
4747
resume_from_checkpoint: False
4848
save_adapter_weights_only: False
4949

@@ -95,7 +95,7 @@ profiler:
9595
enabled: False
9696

9797
# Output directory of trace artifacts
98-
output_dir: /tmp/Phi-3-mini-4k-instruct/profiling_outputs
98+
output_dir: /tmp/Phi-4-mini-16k-instruct/profiling_outputs
9999

100100
#`torch.profiler.ProfilerActivity` types to trace
101101
cpu: True

torchtune/_recipe_registry.py

+14
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class Recipe:
5959
name="phi3/mini_full_low_memory",
6060
file_path="phi3/mini_full_low_memory.yaml",
6161
),
62+
Config(
63+
name="phi4/mini_full_low_memory",
64+
file_path="phi4/mini_full_low_memory.yaml",
65+
),
6266
Config(
6367
name="qwen2/7B_full_single_device",
6468
file_path="qwen2/7B_full_single_device.yaml",
@@ -114,6 +118,7 @@ class Recipe:
114118
Config(name="gemma2/9B_full", file_path="gemma2/9B_full.yaml"),
115119
Config(name="gemma2/27B_full", file_path="gemma2/27B_full.yaml"),
116120
Config(name="phi3/mini_full", file_path="phi3/mini_full.yaml"),
121+
Config(name="phi4/mini_full", file_path="phi4/mini_full.yaml"),
117122
Config(name="qwen2/7B_full", file_path="qwen2/7B_full.yaml"),
118123
Config(name="qwen2/0.5B_full", file_path="qwen2/0.5B_full.yaml"),
119124
Config(name="qwen2/1.5B_full", file_path="qwen2/1.5B_full.yaml"),
@@ -252,6 +257,14 @@ class Recipe:
252257
name="phi3/mini_qlora_single_device",
253258
file_path="phi3/mini_qlora_single_device.yaml",
254259
),
260+
Config(
261+
name="phi4/mini_lora_single_device",
262+
file_path="phi4/mini_lora_single_device.yaml",
263+
),
264+
Config(
265+
name="phi4/mini_qlora_single_device",
266+
file_path="phi4/mini_qlora_single_device.yaml",
267+
),
255268
Config(
256269
name="qwen2/7B_lora_single_device",
257270
file_path="qwen2/7B_lora_single_device.yaml",
@@ -371,6 +384,7 @@ class Recipe:
371384
Config(name="gemma2/9B_lora", file_path="gemma2/9B_lora.yaml"),
372385
Config(name="gemma2/27B_lora", file_path="gemma2/27B_lora.yaml"),
373386
Config(name="phi3/mini_lora", file_path="phi3/mini_lora.yaml"),
387+
Config(name="phi4/mini_lora", file_path="phi3/mini_lora.yaml"),
374388
Config(name="qwen2/7B_lora", file_path="qwen2/7B_lora.yaml"),
375389
Config(name="qwen2/0.5B_lora", file_path="qwen2/0.5B_lora.yaml"),
376390
Config(name="qwen2/1.5B_lora", file_path="qwen2/1.5B_lora.yaml"),

0 commit comments

Comments
 (0)