1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| class ModelSelectionStrategy: """ 模型选择策略 根据场景需求选择最优模型 """ def select_model(self, requirements): """ 选择模型 Args: requirements: { 'latency_budget_ms': 30, 'accuracy_threshold': 90, 'power_budget_mw': 500, 'hardware': 'QCS8255' } Returns: selected_model: 推荐模型 """ candidates = self.get_candidate_models() candidates = [m for m in candidates if m['latency_ms'] <= requirements['latency_budget_ms']] candidates = [m for m in candidates if m['accuracy'] >= requirements['accuracy_threshold']] candidates = [m for m in candidates if m['power_mw'] <= requirements['power_budget_mw']] if not candidates: return None best = max(candidates, key=lambda m: m['accuracy']) return best def get_candidate_models(self): """获取候选模型库""" return [ { 'name': 'DMS-Large-FP32', 'accuracy': 96.0, 'latency_ms': 150, 'power_mw': 2000, 'size_mb': 25 }, { 'name': 'DMS-Medium-INT8', 'accuracy': 93.5, 'latency_ms': 22, 'power_mw': 380, 'size_mb': 3.2 }, { 'name': 'DMS-Small-INT8', 'accuracy': 91.0, 'latency_ms': 15, 'power_mw': 200, 'size_mb': 1.8 } ]
scenario_recommendations = { 'high_performance': { 'latency_budget': 20, 'accuracy_threshold': 93, 'recommendation': 'DMS-Medium-INT8-NPU' }, 'low_power': { 'latency_budget': 30, 'accuracy_threshold': 90, 'power_budget': 300, 'recommendation': 'DMS-Small-INT8-NPU' }, 'maximum_accuracy': { 'latency_budget': 50, 'accuracy_threshold': 95, 'recommendation': 'DMS-Medium-INT8-NPU + QAT' } }
|