<commit_before>import numpy as np
import torch
import torch.nn as nn

from metal.mmtl.utils.utils import stack_batches
from metal.utils import move_to_device, recursive_merge_dicts

model_config = {
    "seed": None,
    "device": 0,  # gpu id (int) or -1 for cpu
    "verbose": True,
}


class MetalModel(nn.Module):
    """A dynamically constructed discriminative classifier

    Args:
        tasks: a list of Task objects which bring their own (named) modules

    We currently support up to N input modules -> middle layers -> up to N heads
    TODO: Accept specifications for more exotic structure (e.g., via user-defined graph)
    """

    def __init__(self, tasks, **kwargs):
        super().__init__()
        self.config = recursive_merge_dicts(model_config, kwargs, misses="insert")
        self._build(tasks)

        # Move model to device now, then move data to device in forward() or calculate_loss()
        if self.config["device"] >= 0:
            if self.config["verbose"]:
                print("Using GPU...")
            self.to(torch.device(f"cuda:{self.config['device']}"))

        # Show network
        if self.config["verbose"]:
            print("\nNetwork architecture:")
            print(self)
            print()<commit_msg>set random seed in metal_model<commit_after>import numpy as np
import torch
import torch.nn as nn

from metal.mmtl.utils.utils import stack_batches
from metal.utils import move_to_device, recursive_merge_dicts

model_config = {"seed": 123, "device": 0, "verbose": True}  # gpu id (int) or -1 for cpu


class MetalModel(nn.Module):
    """A dynamically constructed discriminative classifier

    Args:
        tasks: a list of Task objects which bring their own (named) modules

    We currently support up to N input modules -> middle layers -> up to N heads
    TODO: Accept specifications for more exotic structure (e.g., via user-defined graph)
    """

    def __init__(self, tasks, **kwargs):
        super().__init__()
        self.config = recursive_merge_dicts(model_config, kwargs, misses="insert")
        self._build(tasks)

        # Move model to device now, then move data to device in forward() or calculate_loss()
        if self.config["device"] >= 0:
            if self.config["verbose"]:
                print("Using GPU...")
            self.to(torch.device(f"cuda:{self.config['device']}"))

        # Show network
        if self.config["verbose"]:
            print("\nNetwork architecture:")
            print(self)
            print()
{'fraction_non_alphanumeric': 0.10837633981738785, 'fraction_numerical': 0.003572846367606193, 'mean_word_length': 2.766816143497758, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '208054', 'n_tokens_mistral': 719, 'n_tokens_neox': 685, 'n_words': 239}