cache.py 1.47 KB
Newer Older
Baber's avatar
Baber committed
1
2
3
4
5
import argparse

from lm_eval._cli.base import SubCommand


Baber's avatar
Baber committed
6
class Cache(SubCommand):
Baber's avatar
Baber committed
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
    """Command for cache management."""

    def __init__(self, subparsers: argparse._SubParsersAction, *args, **kwargs):
        # Create and configure the parser
        super().__init__(*args, **kwargs)
        parser = subparsers.add_parser(
            "cache",
            help="Manage evaluation cache",
            description="Manage evaluation cache files and directories.",
            epilog="""
Examples:
  lm-eval cache clear --cache_path ./cache.db     # Clear cache file
  lm-eval cache info --cache_path ./cache.db      # Show cache info
  lm-eval cache clear --cache_path ./cache_dir/   # Clear cache directory
            """,
            formatter_class=argparse.RawDescriptionHelpFormatter,
        )

        # Add command-specific arguments
        self._add_args(parser)

        # Set the function to execute for this subcommand
        parser.set_defaults(func=self.execute)

    def _add_args(self, parser: argparse.ArgumentParser) -> None:
        parser.add_argument(
            "action",
            choices=["clear", "info"],
            help="Action to perform: clear or info",
        )
        parser.add_argument(
            "--cache_path",
            type=str,
            default=None,
            help="Path to cache directory or file",
        )

    def execute(self, args: argparse.Namespace) -> None:
        """Execute the cache command."""
Baber's avatar
Baber committed
46
        raise NotImplementedError