afnio.autodiff.decorators
afnio.autodiff.decorators.evaluator(cls)
Decorator to mark a class as an evaluator within the afnio framework.
This decorator is intended to be applied to classes inheriting from
Function. It sets an internal attribute
_is_evaluator on the class to True, allowing the autodiff engine to recognize
the class as an evaluator. This designation enables the evaluator's
backward function
to be called without any input arguments when computing gradients.
Evaluators are responsible for assessing predictions using either deterministic or language model-based approaches. By using this decorator, users can build their own evaluator classes without worrying about internal setup details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[Function]
|
The class being decorated,
which should inherit from |
required |
Returns:
| Type | Description |
|---|---|
Type[Function]
|
The same class with the |
Examples:
>>> @evaluator
>>> class MyCustomEvaluator(Function):
>>> @staticmethod
>>> def forward(ctx, prediction, target):
>>> # Evaluation logic
>>> pass
>>> @staticmethod
>>> def backward(ctx, grad_output):
>>> # Backpropagation logic
>>> pass
Source code in afnio/autodiff/decorators.py
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 | |