vectorplasticity commited on
Commit
0a98915
·
verified ·
1 Parent(s): 958479d

Update via HuggingFace Tool

Browse files
Files changed (1) hide show
  1. app/routers/models.py +2 -15
app/routers/models.py CHANGED
@@ -12,7 +12,7 @@ import httpx
12
  from app.config import settings
13
 
14
  logger = logging.getLogger(__name__)
15
- router = APIRouter(tags=["Models"])
16
 
17
 
18
  class ModelInfo(BaseModel):
@@ -150,7 +150,6 @@ async def get_model_info(model_id: str):
150
  @router.get("/recommend/{task_type}", response_model=List[ModelRecommendation])
151
  async def get_model_recommendations(task_type: str):
152
  """Get model recommendations for a specific task."""
153
- # Popular models by task type
154
  recommendations = {
155
  "causal-lm": [
156
  ModelRecommendation(model_id="microsoft/phi-2", reason="Compact but powerful, excellent for fine-tuning", estimated_vram="8GB", suggested_batch_size=4, supports_peft=True),
@@ -198,7 +197,6 @@ async def get_model_recommendations(task_type: str):
198
  result = recommendations.get(task_type, [])
199
 
200
  if not result:
201
- # Default to causal-lm recommendations
202
  result = recommendations.get("causal-lm", [])
203
 
204
  return result[:5]
@@ -212,7 +210,6 @@ async def check_model_compatibility(
212
  """Check if a model is compatible for training with current setup."""
213
  async with httpx.AsyncClient() as client:
214
  try:
215
- # Get model info
216
  response = await client.get(
217
  f"{HF_API_URL}/models/{model_id}",
218
  timeout=30.0
@@ -224,28 +221,21 @@ async def check_model_compatibility(
224
  recommendations = []
225
  compatible = True
226
 
227
- # Check library
228
  library = data.get("library_name", "transformers")
229
  if library not in ["transformers", "peft", "adapter-transformers"]:
230
  issues.append(f"Unsupported library: {library}")
231
  compatible = False
232
 
233
- # Check tags
234
  tags = data.get("tags", [])
235
- model_size_tags = [t for t in tags if any(s in t for s in ['b', 'B', 'm', 'M'])]
236
 
237
- # Check for gated models
238
  if "gated" in tags:
239
  recommendations.append("This is a gated model. Ensure you have access and set HF_TOKEN.")
240
 
241
- # Check private models
242
  if data.get("private", False):
243
  recommendations.append("Private model requires authentication.")
244
 
245
- # Estimate requirements
246
  pipeline_tag = data.get("pipeline_tag", "")
247
 
248
- # Determine max sequence length based on model type
249
  if "bert" in model_id.lower():
250
  max_seq_len = 512
251
  elif "llama" in model_id.lower():
@@ -257,7 +247,6 @@ async def check_model_compatibility(
257
  else:
258
  max_seq_len = 2048
259
 
260
- # Check task compatibility
261
  task_pipeline_map = {
262
  "causal-lm": "text-generation",
263
  "seq2seq": "text2text-generation",
@@ -271,9 +260,8 @@ async def check_model_compatibility(
271
 
272
  expected_pipeline = task_pipeline_map.get(task)
273
  if expected_pipeline and pipeline_tag and pipeline_tag != expected_pipeline:
274
- recommendations.append(f"Model pipeline tag ({pipeline_tag}) may not match task ({task}). Consider adjusting task type.")
275
 
276
- # CPU training limitations
277
  requires_gpu = False
278
  model_name_lower = model_id.lower()
279
  if any(x in model_name_lower for x in ["7b", "13b", "30b", "70b"]):
@@ -281,7 +269,6 @@ async def check_model_compatibility(
281
  requires_gpu = True
282
  compatible = False
283
 
284
- # Estimate training time (very rough)
285
  if "7b" in model_id.lower():
286
  training_time = "Hours per epoch on GPU"
287
  elif "2b" in model_id.lower() or "3b" in model_id.lower():
 
12
  from app.config import settings
13
 
14
  logger = logging.getLogger(__name__)
15
+ router = APIRouter(prefix="/api/models", tags=["Models"])
16
 
17
 
18
  class ModelInfo(BaseModel):
 
150
  @router.get("/recommend/{task_type}", response_model=List[ModelRecommendation])
151
  async def get_model_recommendations(task_type: str):
152
  """Get model recommendations for a specific task."""
 
153
  recommendations = {
154
  "causal-lm": [
155
  ModelRecommendation(model_id="microsoft/phi-2", reason="Compact but powerful, excellent for fine-tuning", estimated_vram="8GB", suggested_batch_size=4, supports_peft=True),
 
197
  result = recommendations.get(task_type, [])
198
 
199
  if not result:
 
200
  result = recommendations.get("causal-lm", [])
201
 
202
  return result[:5]
 
210
  """Check if a model is compatible for training with current setup."""
211
  async with httpx.AsyncClient() as client:
212
  try:
 
213
  response = await client.get(
214
  f"{HF_API_URL}/models/{model_id}",
215
  timeout=30.0
 
221
  recommendations = []
222
  compatible = True
223
 
 
224
  library = data.get("library_name", "transformers")
225
  if library not in ["transformers", "peft", "adapter-transformers"]:
226
  issues.append(f"Unsupported library: {library}")
227
  compatible = False
228
 
 
229
  tags = data.get("tags", [])
 
230
 
 
231
  if "gated" in tags:
232
  recommendations.append("This is a gated model. Ensure you have access and set HF_TOKEN.")
233
 
 
234
  if data.get("private", False):
235
  recommendations.append("Private model requires authentication.")
236
 
 
237
  pipeline_tag = data.get("pipeline_tag", "")
238
 
 
239
  if "bert" in model_id.lower():
240
  max_seq_len = 512
241
  elif "llama" in model_id.lower():
 
247
  else:
248
  max_seq_len = 2048
249
 
 
250
  task_pipeline_map = {
251
  "causal-lm": "text-generation",
252
  "seq2seq": "text2text-generation",
 
260
 
261
  expected_pipeline = task_pipeline_map.get(task)
262
  if expected_pipeline and pipeline_tag and pipeline_tag != expected_pipeline:
263
+ recommendations.append(f"Model pipeline tag ({pipeline_tag}) may not match task ({task}).")
264
 
 
265
  requires_gpu = False
266
  model_name_lower = model_id.lower()
267
  if any(x in model_name_lower for x in ["7b", "13b", "30b", "70b"]):
 
269
  requires_gpu = True
270
  compatible = False
271
 
 
272
  if "7b" in model_id.lower():
273
  training_time = "Hours per epoch on GPU"
274
  elif "2b" in model_id.lower() or "3b" in model_id.lower():