Skip to content

config API

maai.models.config

VapConfig dataclass

Configuration class for VAP (Voice Activity Projection) model.

This class holds all the hyperparameters and configuration options required to build and train the VAP model and its variants.

Source code in src/maai/models/config.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
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
@dataclass
class VapConfig:
    """Configuration class for VAP (Voice Activity Projection) model.

    This class holds all the hyperparameters and configuration options
    required to build and train the VAP model and its variants.
    """
    sample_rate: int = 16000
    frame_hz: float = 10.0
    bin_times: List[float] = field(default_factory=lambda: BIN_TIMES)

    # Encoder (training flag)
    encoder_type: str = "cpc"
    mimi_model_name: str = "kyutai/mimi"
    wav2vec_type: str = "mms"
    hubert_model: str = "hubert_jp"
    freeze_encoder: int = 1  # stupid but works (--vap_freeze_encoder 1)
    load_pretrained: int = 1  # stupid but works (--vap_load_pretrained 1)
    only_feature_extraction: int = 0

    # GPT
    dim: int = 256
    channel_layers: int = 1
    cross_layers: int = 3
    num_heads: int = 4
    dropout: float = 0.1
    context_limit: int = -1

    context_limit_cpc_sec: float = -1

    # Added Multi-task
    lid_classify: int = 0   # 1...last layer, 2...middle layer
    lid_classify_num_class: int = 3
    lid_classify_adversarial: int = 0
    lang_cond: int = 0

    # For prompt
    # dim_prompt: int = 1792
    dim_prompt: int = 256
    dim_prompt_2: int = 256

    # --- Nod para(mode=nod_para / MLP 層数・隠れ次元・TaskGPT 層数のみ可変、他は vap_nod_para 内固定)---
    nod_head_mlp_repetitions: int = 1
    nod_head_mlp_range: int = 1
    nod_head_mlp_speed: int = 1
    nod_head_mlp_swing_binary: int = 1
    nod_head_mlp_hidden: int = 128
    nod_task_gpt_layers: int = 2

    @staticmethod
    def add_argparse_args(parser, fields_added=[]):
        """Add VapConfig attributes as command-line arguments to an argparse parser.

        Args:
            parser: The argparse.ArgumentParser instance.
            fields_added (list): A list to keep track of added field names.

        Returns:
            tuple: A tuple containing the updated parser and the fields_added list.
        """
        for k, v in VapConfig.__dataclass_fields__.items():
            if k == "bin_times":
                parser.add_argument(
                    f"--vap_{k}", nargs="+", type=float, default=v.default_factory()
                )
            else:
                parser.add_argument(f"--vap_{k}", type=v.type, default=v.default)
            fields_added.append(k)
        return parser, fields_added

    @staticmethod
    def args_to_conf(args):
        """Convert parsed command-line arguments back into a VapConfig instance.

        Args:
            args: The parsed arguments from argparse.

        Returns:
            VapConfig: A new instance of VapConfig populated with the parsed values.
        """
        return VapConfig(
            **{
                k.replace("vap_", ""): v
                for k, v in vars(args).items()
                if k.startswith("vap_")
            }
        )

add_argparse_args(parser, fields_added=[]) staticmethod

Add VapConfig attributes as command-line arguments to an argparse parser.

Parameters:

Name Type Description Default
parser

The argparse.ArgumentParser instance.

required
fields_added list

A list to keep track of added field names.

[]

Returns:

Name Type Description
tuple

A tuple containing the updated parser and the fields_added list.

Source code in src/maai/models/config.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@staticmethod
def add_argparse_args(parser, fields_added=[]):
    """Add VapConfig attributes as command-line arguments to an argparse parser.

    Args:
        parser: The argparse.ArgumentParser instance.
        fields_added (list): A list to keep track of added field names.

    Returns:
        tuple: A tuple containing the updated parser and the fields_added list.
    """
    for k, v in VapConfig.__dataclass_fields__.items():
        if k == "bin_times":
            parser.add_argument(
                f"--vap_{k}", nargs="+", type=float, default=v.default_factory()
            )
        else:
            parser.add_argument(f"--vap_{k}", type=v.type, default=v.default)
        fields_added.append(k)
    return parser, fields_added

args_to_conf(args) staticmethod

Convert parsed command-line arguments back into a VapConfig instance.

Parameters:

Name Type Description Default
args

The parsed arguments from argparse.

required

Returns:

Name Type Description
VapConfig

A new instance of VapConfig populated with the parsed values.

Source code in src/maai/models/config.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@staticmethod
def args_to_conf(args):
    """Convert parsed command-line arguments back into a VapConfig instance.

    Args:
        args: The parsed arguments from argparse.

    Returns:
        VapConfig: A new instance of VapConfig populated with the parsed values.
    """
    return VapConfig(
        **{
            k.replace("vap_", ""): v
            for k, v in vars(args).items()
            if k.startswith("vap_")
        }
    )