Spaces:
Runtime error
Runtime error
Update retriever.py
Browse files- retriever.py +22 -16
retriever.py
CHANGED
|
@@ -2,7 +2,7 @@ from smolagents import Tool
|
|
| 2 |
|
| 3 |
class FrugalAI_methods(Tool):
|
| 4 |
name = "FrugalAI_methods"
|
| 5 |
-
description = "Retrieves methods for model frugalization."
|
| 6 |
inputs = {
|
| 7 |
"method": {
|
| 8 |
"type": "string",
|
|
@@ -10,25 +10,31 @@ class FrugalAI_methods(Tool):
|
|
| 10 |
}
|
| 11 |
}
|
| 12 |
output_type = "string"
|
| 13 |
-
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
f"To apply pruning to a model, use the following code snippet: {code}. "
|
| 23 |
f"You should adapt it to your actual implementation. In particular, the 'amount' parameter "
|
| 24 |
f"can be increased or decreased depending on the initial number of weights and the complexity of your use case (minimu value: 0, maximum value: 1)."
|
| 25 |
)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
f"To apply quantization to a model, use the following code snippet: {code}."
|
| 34 |
)
|
|
|
|
| 2 |
|
| 3 |
class FrugalAI_methods(Tool):
|
| 4 |
name = "FrugalAI_methods"
|
| 5 |
+
description = "Retrieves methods for model frugalization. It will return ideas to frugalize a code, please use it."
|
| 6 |
inputs = {
|
| 7 |
"method": {
|
| 8 |
"type": "string",
|
|
|
|
| 10 |
}
|
| 11 |
}
|
| 12 |
output_type = "string"
|
| 13 |
+
|
| 14 |
+
def forward(self, method):
|
| 15 |
+
ideas=[]
|
| 16 |
+
ideas.append(pruning())
|
| 17 |
+
ideas.append(quantization())
|
| 18 |
+
return ideas
|
| 19 |
+
|
| 20 |
+
def pruning(self,method: str):
|
| 21 |
+
"""
|
| 22 |
+
Optimizes models by removing unnecessary components, such as certain weights in a neural network.
|
| 23 |
+
This function demonstrates how to apply pruning.
|
| 24 |
+
"""
|
| 25 |
+
model = apply_pruning(model, amount=0.3)
|
| 26 |
+
code = "model = apply_pruning(model, amount=0.3)"
|
| 27 |
+
return (
|
| 28 |
f"To apply pruning to a model, use the following code snippet: {code}. "
|
| 29 |
f"You should adapt it to your actual implementation. In particular, the 'amount' parameter "
|
| 30 |
f"can be increased or decreased depending on the initial number of weights and the complexity of your use case (minimu value: 0, maximum value: 1)."
|
| 31 |
)
|
| 32 |
|
| 33 |
+
def quantization(self, method: str):
|
| 34 |
+
"""
|
| 35 |
+
Converts high-precision weights into lower-precision one to reduce cost.
|
| 36 |
+
"""
|
| 37 |
+
code = "model = torch.quantization.quantize_dynamic(model, dtype=torch.qint8)"
|
| 38 |
+
return (
|
| 39 |
f"To apply quantization to a model, use the following code snippet: {code}."
|
| 40 |
)
|