Skip to content

Commit

Permalink
add phi2 model conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
guotuofeng committed Jan 9, 2024
1 parent 7b8a267 commit a9f4cf7
Show file tree
Hide file tree
Showing 4 changed files with 406 additions and 0 deletions.
103 changes: 103 additions & 0 deletions examples/phi2/phi2_optimize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"input_model": {
"type": "PyTorchModel",
"config": {
"model_loader": "model_loader",
"model_script": "user_script.py",
"dummy_inputs_func": "dummy_inputs",
"io_config": "get_io_config",
"hf_config": {
"model_name": "microsoft/phi-2",
"task": "text-generation",
"from_pretrained_args": {
"trust_remote_code": true
}
}
}
},
"systems": {
"local_system": {
"type": "LocalSystem",
"config": {
"accelerators": [
"cpu"
]
}
}
},
"evaluators": {
"common_evaluator": {
"metrics": [
{
"name": "latency",
"type": "latency",
"sub_types": [
{
"name": "avg",
"priority": 1
}
],
"user_config": {
"user_script": "user_script.py",
"dataloader_func": "create_dataloader",
"batch_size": 2,
"inference_settings": {
"onnx": {
"session_options": {
"enable_profiling": false
}
}
}
}
}
]
}
},
"passes": {
"convert_optimum": {
"type": "OptimumConversion",
"config": {
"target_opset": 14,
"extra_args": {
"legacy": false,
"no_post_process": false,
"trust_remote_code": true
}
}
},
"convert": {
"type": "OnnxConversion",
"config": {
"target_opset": 17,
"save_as_external_data": true,
"all_tensors_to_one_file": true
}
},
"perf_tuning": {
"type": "OrtPerfTuning",
"config": {
"user_script": "user_script.py",
"dataloader_func": "create_dataloader",
"batch_size": 2,
"enable_profiling": false
}
}
},
"pass_flows": [
[
"convert"
]
],
"engine": {
"search_strategy": false,
"evaluate_input_model": false,
"evaluator": "common_evaluator",
"target": "local_system",
"cache_dir": "cache",
"output_name": "phi2",
"output_dir": "phi2",
"clean_cache": false,
"log_severity_level": 0,
"log_to_file": false
}
}
10 changes: 10 additions & 0 deletions examples/phi2/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Prerequisites
* einops

## Usage
```bash
python -m olive.workflows.run --config phi2_optimize.json
```

## Limitations
From the time being, the official [phi2](https://huggingface.co/microsoft/phi-2) model could not be exported to ONNX by using the offical model code. Therefore, we need patch the forward method to do preprocessing and postprocessing for the past_key_values arguments. When the official model could be exported to ONNX, we will remove this patch.

Check notice on line 10 in examples/phi2/readme.md

View workflow job for this annotation

GitHub Actions / misspell

[misspell] examples/phi2/readme.md#L10

"offical" is a misspelling of "official"
Raw output
./examples/phi2/readme.md:10:130: "offical" is a misspelling of "official"
1 change: 1 addition & 0 deletions examples/phi2/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
einops
Loading

0 comments on commit a9f4cf7

Please sign in to comment.