Views
No views yet
1# Install the base package
2uv syncuv run python distill.py --pca_dims 384--model_name - Source model name (default: "Qodo/Qodo-Embed-1-1.5B")--output_dir - Where to save the distilled model (default: "models/qodo_embed_m2v")--pca_dims - Dimensions for PCA reduction; smaller values create faster but less accurate models (default: 384)--save_to_hub - Push the model to HuggingFace Hub--hub_model_id - Model ID for HuggingFace Hub (required if saving to hub)--skip_readme - Skip generating README file (default: True)uv run python evaluate.py--original_model - Original model name (default: "Qodo/Qodo-Embed-1-1.5B")--distilled_model - Path to the distilled model (default: ".")--output_dir - Where to save evaluation results (default: "evaluation")1from model2vec import StaticModel
2from sentence_transformers import SentenceTransformer
3import time
4
5# Sample code for embedding
6code_samples = [
7 "def process_data_stream(source_iterator):",
8 "implement binary search tree",
9 "how to handle memory efficient data streaming",
10 """class LazyLoader:
11 def __init__(self, source):
12 self.generator = iter(source)
13 self._cache = []"""
14]
15
16# Load original model
17print("Loading original model...")
18original_model = SentenceTransformer("Qodo/Qodo-Embed-1-1.5B")
19
20# Load distilled model
21print("Loading distilled model...")
22distilled_model = StaticModel.from_pretrained("models/qodo_embed_m2v")
23
24# Compare embedding speed
25print("\nGenerating embeddings with original model...")
26start = time.time()
27original_embeddings = original_model.encode(code_samples)
28original_time = time.time() - start
29print(f"Original model took: {original_time:.4f} seconds")
30
31print("\nGenerating embeddings with distilled model...")
32start = time.time()
33distilled_embeddings = distilled_model.encode(code_samples)
34distilled_time = time.time() - start
35print(f"Distilled model took: {distilled_time:.4f} seconds")
36print(f"Speed improvement: {original_time/distilled_time:.2f}x faster")
37
38print(f"\nOriginal embedding dimensions: {original_embeddings.shape}")
39print(f"Distilled embedding dimensions: {distilled_embeddings.shape}")distill.py - Script to create the distilled modelevaluate.py - Script to compare performance with the original modelexample.py - Example usage of the distilled modelevaluation/ - Directory containing evaluation results and visualizations