mimic-kit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Mimic-Kit Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: mimic-kit
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.13
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: click>=8.0.0
9
+ Requires-Dist: deepspeed>=0.18.7
10
+ Requires-Dist: diskcache>=5.6.3
11
+ Requires-Dist: liger-kernel>=0.7.0
12
+ Requires-Dist: mpi4py>=4.1.1
13
+ Requires-Dist: ms-swift>=4.0.1
14
+ Requires-Dist: openai>=1.0.0
15
+ Requires-Dist: peft>=0.6.2
16
+ Requires-Dist: pydantic>=2.12.5
17
+ Requires-Dist: pyyaml>=6.0.3
18
+ Requires-Dist: torch>=2.10.0
19
+ Requires-Dist: transformers[torch]>=5.2.0
20
+ Dynamic: license-file
21
+
22
+ # Mimic-Kit
23
+
24
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
26
+
27
+ [δΈ­ζ–‡ζ–‡ζ‘£](README-ZH.md) | **English**
28
+
29
+ Mimic-Kit is a **black-box knowledge distillation scaffolding** that helps you distill capabilities from powerful teacher models into smaller, more efficient student models.
30
+
31
+ ## Features
32
+
33
+ - πŸ€– **Teacher Model Generation**: Use OpenAI API (or compatible APIs) to generate high-quality training data
34
+ - πŸš€ **Efficient Training**: Built on [ms-swift](https://github.com/modelscope/swift) for streamlined model training
35
+ - 🧩 **Flexible Tuning**: Support both LoRA (parameter-efficient) and full fine-tuning
36
+ - ⚑ **Performance Optimized**: Integrated with DeepSpeed and Liger Kernel for accelerated training
37
+ - πŸ’Ύ **Smart Caching**: Automatically cache API responses to save costs
38
+ - πŸ“Š **Multiple Data Formats**: Support both chat and text completion formats
39
+
40
+ ## Quick Start
41
+
42
+ ### 1. Installation
43
+
44
+ ```bash
45
+ # Clone the repository
46
+ git clone <repository-url>
47
+ cd mimic-kit
48
+
49
+ # Install dependencies using UV
50
+ uv sync
51
+
52
+ # Or with dev dependencies
53
+ uv sync --group dev
54
+ ```
55
+
56
+ ### 2. Initialize Configuration
57
+
58
+ ```bash
59
+ uv run mimic init
60
+ ```
61
+
62
+ This creates a `config.yaml` template. Edit it to configure your teacher model, student model, and training parameters.
63
+
64
+ ### 3. Prepare Your Data
65
+
66
+ Create a JSONL file with your prompts. Supports two formats:
67
+
68
+ **Chat Format:**
69
+ ```jsonl
70
+ {"messages": [{"role": "user", "content": "Explain Python decorators"}]}
71
+ {"messages": [{"role": "user", "content": "How to reverse a linked list?"}]}
72
+ ```
73
+
74
+ **Text Completion Format:**
75
+ ```jsonl
76
+ {"text": "Python decorators are a powerful feature..."}
77
+ {"text": "To reverse a linked list, you need to..."}
78
+ ```
79
+
80
+ ### 4. Generate Training Data
81
+
82
+ ```bash
83
+ uv run mimic generate
84
+ ```
85
+
86
+ This sends your prompts to the teacher model and saves the generated responses as training data.
87
+
88
+ ### 5. Train Your Student Model
89
+
90
+ ```bash
91
+ uv run mimic train
92
+ ```
93
+
94
+ The student model will be fine-tuned on the generated data using the configured method (LoRA or full fine-tuning).
95
+
96
+ ## Configuration
97
+
98
+ See `config.yaml` for all available options. Key sections:
99
+
100
+ - `data`: Input/output paths, system prompts, templates
101
+ - `teacher`: API provider, model, generation parameters
102
+ - `student`: Base model, tuning method, hyperparameters
103
+ - `training`: Batch size, learning rate, saving strategy
104
+
105
+ ## Project Structure
106
+
107
+ ```
108
+ mimic-kit/
109
+ β”œβ”€β”€ mimic/
110
+ β”‚ β”œβ”€β”€ cli.py # CLI entry point
111
+ β”‚ β”œβ”€β”€ config.py # Configuration models (Pydantic v2)
112
+ β”‚ β”œβ”€β”€ generator/ # Teacher model data generation
113
+ β”‚ └── trainer/ # Student model training (ms-swift)
114
+ β”œβ”€β”€ data/ # Training data directory
115
+ β”œβ”€β”€ config.yaml # Your configuration file
116
+ └── output/ # Model outputs and checkpoints
117
+ ```
118
+
119
+ ## Requirements
120
+
121
+ - Python 3.13+
122
+ - CUDA-capable GPU (for training)
123
+ - OpenAI API key (or compatible API)
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ # Run tests
129
+ uv run pytest
130
+
131
+ # Run single test
132
+ uv run pytest tests/test_cli.py::test_function
133
+
134
+ # Format code
135
+ uv run ruff format .
136
+
137
+ # Check linting
138
+ uv run ruff check .
139
+ ```
140
+
141
+ ## License
142
+
143
+ MIT License - see [LICENSE](LICENSE) file for details.
144
+
145
+ ## Acknowledgments
146
+
147
+ - Built with [ms-swift](https://github.com/modelscope/swift) for model training
148
+ - Uses [Pydantic](https://docs.pydantic.dev/) for configuration validation
149
+ - Powered by [Click](https://click.palletsprojects.com/) for CLI
@@ -0,0 +1,128 @@
1
+ # Mimic-Kit
2
+
3
+ [![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+
6
+ [δΈ­ζ–‡ζ–‡ζ‘£](README-ZH.md) | **English**
7
+
8
+ Mimic-Kit is a **black-box knowledge distillation scaffolding** that helps you distill capabilities from powerful teacher models into smaller, more efficient student models.
9
+
10
+ ## Features
11
+
12
+ - πŸ€– **Teacher Model Generation**: Use OpenAI API (or compatible APIs) to generate high-quality training data
13
+ - πŸš€ **Efficient Training**: Built on [ms-swift](https://github.com/modelscope/swift) for streamlined model training
14
+ - 🧩 **Flexible Tuning**: Support both LoRA (parameter-efficient) and full fine-tuning
15
+ - ⚑ **Performance Optimized**: Integrated with DeepSpeed and Liger Kernel for accelerated training
16
+ - πŸ’Ύ **Smart Caching**: Automatically cache API responses to save costs
17
+ - πŸ“Š **Multiple Data Formats**: Support both chat and text completion formats
18
+
19
+ ## Quick Start
20
+
21
+ ### 1. Installation
22
+
23
+ ```bash
24
+ # Clone the repository
25
+ git clone <repository-url>
26
+ cd mimic-kit
27
+
28
+ # Install dependencies using UV
29
+ uv sync
30
+
31
+ # Or with dev dependencies
32
+ uv sync --group dev
33
+ ```
34
+
35
+ ### 2. Initialize Configuration
36
+
37
+ ```bash
38
+ uv run mimic init
39
+ ```
40
+
41
+ This creates a `config.yaml` template. Edit it to configure your teacher model, student model, and training parameters.
42
+
43
+ ### 3. Prepare Your Data
44
+
45
+ Create a JSONL file with your prompts. Supports two formats:
46
+
47
+ **Chat Format:**
48
+ ```jsonl
49
+ {"messages": [{"role": "user", "content": "Explain Python decorators"}]}
50
+ {"messages": [{"role": "user", "content": "How to reverse a linked list?"}]}
51
+ ```
52
+
53
+ **Text Completion Format:**
54
+ ```jsonl
55
+ {"text": "Python decorators are a powerful feature..."}
56
+ {"text": "To reverse a linked list, you need to..."}
57
+ ```
58
+
59
+ ### 4. Generate Training Data
60
+
61
+ ```bash
62
+ uv run mimic generate
63
+ ```
64
+
65
+ This sends your prompts to the teacher model and saves the generated responses as training data.
66
+
67
+ ### 5. Train Your Student Model
68
+
69
+ ```bash
70
+ uv run mimic train
71
+ ```
72
+
73
+ The student model will be fine-tuned on the generated data using the configured method (LoRA or full fine-tuning).
74
+
75
+ ## Configuration
76
+
77
+ See `config.yaml` for all available options. Key sections:
78
+
79
+ - `data`: Input/output paths, system prompts, templates
80
+ - `teacher`: API provider, model, generation parameters
81
+ - `student`: Base model, tuning method, hyperparameters
82
+ - `training`: Batch size, learning rate, saving strategy
83
+
84
+ ## Project Structure
85
+
86
+ ```
87
+ mimic-kit/
88
+ β”œβ”€β”€ mimic/
89
+ β”‚ β”œβ”€β”€ cli.py # CLI entry point
90
+ β”‚ β”œβ”€β”€ config.py # Configuration models (Pydantic v2)
91
+ β”‚ β”œβ”€β”€ generator/ # Teacher model data generation
92
+ β”‚ └── trainer/ # Student model training (ms-swift)
93
+ β”œβ”€β”€ data/ # Training data directory
94
+ β”œβ”€β”€ config.yaml # Your configuration file
95
+ └── output/ # Model outputs and checkpoints
96
+ ```
97
+
98
+ ## Requirements
99
+
100
+ - Python 3.13+
101
+ - CUDA-capable GPU (for training)
102
+ - OpenAI API key (or compatible API)
103
+
104
+ ## Development
105
+
106
+ ```bash
107
+ # Run tests
108
+ uv run pytest
109
+
110
+ # Run single test
111
+ uv run pytest tests/test_cli.py::test_function
112
+
113
+ # Format code
114
+ uv run ruff format .
115
+
116
+ # Check linting
117
+ uv run ruff check .
118
+ ```
119
+
120
+ ## License
121
+
122
+ MIT License - see [LICENSE](LICENSE) file for details.
123
+
124
+ ## Acknowledgments
125
+
126
+ - Built with [ms-swift](https://github.com/modelscope/swift) for model training
127
+ - Uses [Pydantic](https://docs.pydantic.dev/) for configuration validation
128
+ - Powered by [Click](https://click.palletsprojects.com/) for CLI
@@ -0,0 +1,3 @@
1
+ """Mimic - A command line tool"""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,115 @@
1
+ """CLI commands for mimic."""
2
+
3
+ from pathlib import Path
4
+
5
+ import click
6
+ from mimic import __version__
7
+ from mimic.config import load_config
8
+ from mimic.generator import generate_dataset, save_dataset
9
+ from mimic.templates import write_config_template
10
+ from mimic.trainer import train_with_swift
11
+
12
+
13
+ @click.group()
14
+ @click.version_option(version=__version__)
15
+ def cli():
16
+ """Mimic - A command line tool to distill models"""
17
+ pass
18
+
19
+
20
+ @cli.command()
21
+ @click.option(
22
+ "--output",
23
+ "-o",
24
+ default="config.yaml",
25
+ help="Output file path (default: config.yaml)",
26
+ )
27
+ @click.option("--force", "-f", is_flag=True, help="Overwrite existing file")
28
+ def init(output, force):
29
+ """Initialize a new config.yaml template file"""
30
+ try:
31
+ write_config_template(output, force=force)
32
+ click.echo(f"Created config template: {output}")
33
+ except FileExistsError as e:
34
+ click.echo(f"Error: {e}. Use --force to overwrite.", err=True)
35
+ raise click.Abort()
36
+
37
+
38
+ @cli.command()
39
+ @click.option(
40
+ "--config",
41
+ "-c",
42
+ default="config.yaml",
43
+ help="Path to configuration file (default: config.yaml)",
44
+ )
45
+ def generate(config):
46
+ """Generate training data using teacher model"""
47
+ try:
48
+ # Load configuration
49
+ cfg = load_config(config)
50
+ click.echo(f"Loaded configuration from {config}")
51
+
52
+ # Generate dataset
53
+ data = generate_dataset(cfg)
54
+
55
+ # Save results
56
+ if data:
57
+ save_dataset(data, cfg.data.dataset_path)
58
+ else:
59
+ click.echo("Warning: No data was generated", err=True)
60
+ raise click.Abort()
61
+
62
+ except FileNotFoundError as e:
63
+ click.echo(f"Error: {e}", err=True)
64
+ raise click.Abort()
65
+ except Exception as e:
66
+ click.echo(f"Error: {e}", err=True)
67
+ raise click.Abort()
68
+
69
+
70
+ @cli.command()
71
+ @click.option(
72
+ "--config",
73
+ "-c",
74
+ default="config.yaml",
75
+ help="Path to configuration file (default: config.yaml)",
76
+ )
77
+ def train(config):
78
+ """Train student model using ms-swift"""
79
+ try:
80
+ # Load configuration
81
+ cfg = load_config(config)
82
+ click.echo(f"Loaded configuration from {config}")
83
+
84
+ # Check if dataset exists
85
+ dataset_path = Path(cfg.data.dataset_path)
86
+ if not dataset_path.exists():
87
+ click.echo(
88
+ f"Error: Dataset not found at {dataset_path}. "
89
+ "Run 'mimic generate' first.",
90
+ err=True,
91
+ )
92
+ raise click.Abort()
93
+
94
+ click.echo(f"Starting training with ms-swift...")
95
+ click.echo(f"Base model: {cfg.student.base_model}")
96
+ click.echo(f"Dataset: {cfg.data.dataset_path}")
97
+
98
+ # Run training
99
+ train_with_swift(cfg)
100
+
101
+ click.echo("Training completed successfully!")
102
+
103
+ except FileNotFoundError as e:
104
+ click.echo(f"Error: {e}", err=True)
105
+ raise click.Abort()
106
+ except RuntimeError as e:
107
+ click.echo(f"Training error: {e}", err=True)
108
+ raise click.Abort()
109
+ except Exception as e:
110
+ click.echo(f"Error: {e}", err=True)
111
+ raise click.Abort()
112
+
113
+
114
+ if __name__ == "__main__":
115
+ cli()