Alikestocode commited on
Commit
35d8225
·
1 Parent(s): e9f4b24

Fix oneshot() API: use correct parameter names from documentation

Browse files

- Change 'model_id' to 'model'
- Change 'modifiers' to 'recipe' (list of modifiers)
- Change 'calibration_data' to 'dataset' (list of strings)
- Remove 'token' parameter (not needed)
- Add optional 'max_seq_length' and 'num_calibration_samples'
- Based on official llm-compressor documentation

Files changed (1) hide show
  1. quantize_to_awq_colab.ipynb +17 -25
quantize_to_awq_colab.ipynb CHANGED
@@ -346,36 +346,28 @@
346
  " print(f\" ✅ AWQModifier created successfully\")\n",
347
  " \n",
348
  " # Call oneshot with the modifier\n",
349
- " # Note: oneshot() uses HfArgumentParser - check actual API for correct parameter names\n",
 
350
  " print(f\" → Starting quantization process...\")\n",
351
  " \n",
352
  " # Prepare calibration dataset (limit to reasonable size)\n",
353
  " calibration_dataset = calibration_texts[:min(calibration_dataset_size, 128)]\n",
354
  " \n",
355
- " # Try different parameter combinations based on oneshot() API\n",
356
- " # The error suggests 'calibration_data', 'modifiers', 'token' aren't recognized\n",
357
- " # Let's try the most common parameter names\n",
358
- " try:\n",
359
- " # Attempt 1: Try with model_id, modifiers, dataset, token\n",
360
- " oneshot(\n",
361
- " model_id=repo_id,\n",
362
- " output_dir=temp_output_dir,\n",
363
- " modifiers=modifiers,\n",
364
- " dataset=calibration_dataset,\n",
365
- " token=os.environ.get(\"HF_TOKEN\")\n",
366
- " )\n",
367
- " except ValueError as e:\n",
368
- " if \"not used by the HfArgumentParser\" in str(e):\n",
369
- " # Attempt 2: Try with just model_id and output_dir, pass rest via kwargs\n",
370
- " print(f\" ⚠️ Parameter names incorrect, trying alternative API...\")\n",
371
- " # Check if oneshot accepts **kwargs or needs different structure\n",
372
- " # For now, try minimal parameters\n",
373
- " oneshot(\n",
374
- " model_id=repo_id,\n",
375
- " output_dir=temp_output_dir\n",
376
- " )\n",
377
- " else:\n",
378
- " raise\n",
379
  " \n",
380
  " print(f\"✅ Model quantized to AWQ successfully\")\n",
381
  " except Exception as e:\n",
 
346
  " print(f\" ✅ AWQModifier created successfully\")\n",
347
  " \n",
348
  " # Call oneshot with the modifier\n",
349
+ " # Correct API based on llm-compressor documentation:\n",
350
+ " # oneshot(model, dataset, recipe, output_dir, max_seq_length, num_calibration_samples)\n",
351
  " print(f\" → Starting quantization process...\")\n",
352
  " \n",
353
  " # Prepare calibration dataset (limit to reasonable size)\n",
354
  " calibration_dataset = calibration_texts[:min(calibration_dataset_size, 128)]\n",
355
  " \n",
356
+ " # oneshot() API parameters:\n",
357
+ " # - model: model ID or path\n",
358
+ " # - dataset: dataset name (string) or list of calibration strings\n",
359
+ " # - recipe: list of modifiers\n",
360
+ " # - output_dir: output directory\n",
361
+ " # - max_seq_length: optional, max sequence length\n",
362
+ " # - num_calibration_samples: optional, number of calibration samples\n",
363
+ " oneshot(\n",
364
+ " model=repo_id,\n",
365
+ " dataset=calibration_dataset, # List of calibration strings\n",
366
+ " recipe=modifiers, # List of modifiers (e.g., [AWQModifier(...)])\n",
367
+ " output_dir=temp_output_dir,\n",
368
+ " max_seq_length=2048, # Optional: max sequence length\n",
369
+ " num_calibration_samples=len(calibration_dataset) # Optional: number of samples\n",
370
+ " )\n",
 
 
 
 
 
 
 
 
 
371
  " \n",
372
  " print(f\"✅ Model quantized to AWQ successfully\")\n",
373
  " except Exception as e:\n",