File size: 2,614 Bytes
d15cd64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f62b8c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d15cd64
 
 
 
 
 
f62b8c4
 
 
 
 
 
 
 
 
 
 
d15cd64
f62b8c4
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
from compliance_checks.base import ComplianceResult, ComplianceCheck, walk_to_next_heading
from bs4 import BeautifulSoup


class ComputationalRequirementsResult(ComplianceResult):
    name = "Computational Requirements"

    def __init__(
            self,
            requirements: str = None,
            *args,
            **kwargs,
    ):
        super().__init__(*args, **kwargs)
        self.requirements = requirements

    def __eq__(self, other):
        if isinstance(other, ComputationalRequirementsResult):
            if super().__eq__(other):
                try:
                    # TODO: Do I want to do a deep equal?
                    # assert self.requirements == other.requirements
                    return True
                except AssertionError:
                    return False
        else:
            return False

    def to_string(self):
        if self.status:
            return """\
            In order for users to know what kind of hardware and software they need to run a model, a model card \
            should have information about the model's computational requirements. We found some documentation \
            for this in this model card. We look for this by searching for a heading called "Technical Specifications".
            """
        else:
            return """\
            We weren't able to find a section in this model card for the model's computational requirements, but it's \
            easy to add one! You can add the following section to the model card and, once you fill in the \
            `[More Information Needed]` sections, the "Computational Requirements" check should pass 🤗

            ```md
            ## Technical Specifications [optional]
            
            ### Compute Infrastructure
            
            [More Information Needed]
            
            #### Hardware
            
            [More Information Needed]
            
            #### Software
            
            [More Information Needed]
            ```
            """


class ComputationalRequirementsCheck(ComplianceCheck):
    name = "Computational Requirements"

    def run_check(self, card: BeautifulSoup):
        combos = [
            ("h2", "Technical Specifications"),
            ("h2", "Technical Specifications [optional]"),
        ]

        for hX, heading in combos:
            purpose_check = walk_to_next_heading(card, hX, heading)
            if purpose_check:
                return ComputationalRequirementsResult(
                    status=True,
                )

        return ComputationalRequirementsResult()