LiamKhoaLe commited on
Commit
a077f52
·
1 Parent(s): b9c2d22

Migrate model debug on app

Browse files
Files changed (2) hide show
  1. app.py +6 -0
  2. download_model.py +15 -7
app.py CHANGED
@@ -66,6 +66,12 @@ for root, dirs, files in os.walk(MODEL_CACHE_DIR):
66
  print(f"📁 {root}/")
67
  for file in files:
68
  print(f" 📄 {file}")
 
 
 
 
 
 
69
  # Check if the required model files exist
70
  snapshots_path = os.path.join(MODEL_CACHE_DIR, "models--sentence-transformers--all-MiniLM-L6-v2/snapshots")
71
  if os.path.exists(snapshots_path):
 
66
  print(f"📁 {root}/")
67
  for file in files:
68
  print(f" 📄 {file}")
69
+ # Ensure all necessary files exist
70
+ required_files = ["config.json", "pytorch_model.bin", "tokenizer.json", "1_Pooling/config.json"]
71
+ for f in required_files:
72
+ if not os.path.exists(os.path.join(MODEL_CACHE_DIR, f)):
73
+ print(f"❌ Missing required model file: {f}")
74
+ exit(1)
75
  # Check if the required model files exist
76
  snapshots_path = os.path.join(MODEL_CACHE_DIR, "models--sentence-transformers--all-MiniLM-L6-v2/snapshots")
77
  if os.path.exists(snapshots_path):
download_model.py CHANGED
@@ -8,27 +8,35 @@ MODEL_CACHE_DIR = "/app/model_cache"
8
 
9
  print("⏳ Downloading the SentenceTransformer model...")
10
  model_path = snapshot_download(repo_id=MODEL_REPO, cache_dir=MODEL_CACHE_DIR)
11
- print("Model path now: ", model_path)
12
 
13
  # Find the correct snapshot directory
14
- # snapshots_dir = os.path.join(model_path, "snapshots") # snapshot
15
  snapshots_dir = model_path
16
  if os.path.exists(snapshots_dir):
17
  snapshot_folders = os.listdir(snapshots_dir)
18
  if snapshot_folders:
19
  snapshot_dir = os.path.join(snapshots_dir, snapshot_folders[0]) # Get first snapshot folder
20
  print(f"📂 Moving model files from {snapshot_dir} to {MODEL_CACHE_DIR}...")
21
- # Move files from snapshot directory to model cache directory
22
- for filename in os.listdir(snapshot_dir):
23
- shutil.move(os.path.join(snapshot_dir, filename), os.path.join(MODEL_CACHE_DIR, filename))
24
- print(f"✅ Model extracted to {MODEL_CACHE_DIR}")
 
 
 
 
 
 
 
25
  else:
26
  print("❌ No snapshot folder found!")
 
27
  else:
28
  print("❌ No snapshots directory found!")
 
29
 
30
  # Verify structure
31
- print("\n📂 LLM Model Structure:")
32
  for root, dirs, files in os.walk(MODEL_CACHE_DIR):
33
  print(f"📁 {root}/")
34
  for file in files:
 
8
 
9
  print("⏳ Downloading the SentenceTransformer model...")
10
  model_path = snapshot_download(repo_id=MODEL_REPO, cache_dir=MODEL_CACHE_DIR)
 
11
 
12
  # Find the correct snapshot directory
13
+ # snapshots_dir = os.path.join(model_path, "snapshots")
14
  snapshots_dir = model_path
15
  if os.path.exists(snapshots_dir):
16
  snapshot_folders = os.listdir(snapshots_dir)
17
  if snapshot_folders:
18
  snapshot_dir = os.path.join(snapshots_dir, snapshot_folders[0]) # Get first snapshot folder
19
  print(f"📂 Moving model files from {snapshot_dir} to {MODEL_CACHE_DIR}...")
20
+
21
+ # Move all model files (including subdirectories)
22
+ for item in os.listdir(snapshot_dir):
23
+ source_path = os.path.join(snapshot_dir, item)
24
+ dest_path = os.path.join(MODEL_CACHE_DIR, item)
25
+ if os.path.isdir(source_path):
26
+ shutil.move(source_path, dest_path)
27
+ else:
28
+ shutil.move(source_path, dest_path)
29
+
30
+ print(f"✅ Model extracted and flattened in {MODEL_CACHE_DIR}")
31
  else:
32
  print("❌ No snapshot folder found!")
33
+ exit(1)
34
  else:
35
  print("❌ No snapshots directory found!")
36
+ exit(1)
37
 
38
  # Verify structure
39
+ print("\n📂 LLM Model Structure (Final):")
40
  for root, dirs, files in os.walk(MODEL_CACHE_DIR):
41
  print(f"📁 {root}/")
42
  for file in files: