tahamajs's picture
download
raw
4.48 kB
import torch
from typing import Dict, Any
MODEL_CONFIGS = {
"seq2seq": {
"vocab_size": 1000,
"embedding_dim": 256,
"hidden_dim": 512,
"num_layers": 2,
"dropout": 0.1,
},
"transformer": {
"vocab_size": 1000,
"d_model": 512,
"nhead": 8,
"num_layers": 6,
"dropout": 0.1,
"max_len": 5000,
},
"graph": {
"vocab_size": 1000,
"embedding_dim": 256,
"hidden_dim": 512,
"num_layers": 3,
},
}
TRAINING_CONFIGS = {
"batch_size": 32,
"learning_rate": 0.001,
"num_epochs": 100,
"max_length": 100,
"patience": 10,
"checkpoints_every": 10,
"gradient_clip": 1.0,
"weight_decay": 1e-5,
}
DATA_CONFIGS = {
"train_size": 1000,
"val_size": 200,
"test_size": 300,
"train_ratio": 0.7,
"val_ratio": 0.15,
"test_ratio": 0.15,
"seed": 42,
}
TASK_CONFIGS = {
"arithmetic": {
"templates": [
"result = {a} + {b}",
"result = {a} - {b}",
"result = {a} * {b}",
"result = {a} / {b}",
"result = pow({a}, 2) + {b}",
"result = abs({a} - {b})",
],
"descriptions": [
"add {a} and {b}",
"subtract {b} from {a}",
"multiply {a} by {b}",
"divide {a} by {b}",
"square {a} and add {b}",
"absolute difference of {a} and {b}",
],
"value_range": (1, 100),
},
"string": {
"templates": [
"result = '{a}' + '{b}'",
"result = '{a}'.upper()",
"result = '{a}'.lower()",
"result = len('{a}')",
"result = '{a}'[::-1]",
],
"descriptions": [
"concatenate '{a}' and '{b}'",
"convert '{a}' to uppercase",
"convert '{a}' to lowercase",
"length of '{a}'",
"reverse of '{a}'",
],
"strings": ["hello", "world", "python", "program", "synthesis"],
},
"list_ops": {
"templates": [
"result = len({a})",
"result = sum({a})",
"result = max({a})",
"result = min({a})",
"result = {a}[0] + {a}[-1]",
],
"descriptions": [
"length of {a}",
"sum all numbers in {a}",
"maximum value in {a}",
"minimum value in {a}",
"add first and last elements of {a}",
],
"list_length_range": (3, 10),
"value_range": (1, 100),
},
}
EVALUATION_CONFIGS = {
"syntax_check": True,
"functional_check": True,
"num_candidates": 1,
"temperature": 1.0,
"max_generation_length": 100,
"executor": "python",
}
DEVICE_CONFIGS = {
"auto": True,
"prefer_cuda": True,
"fallback_cpu": True,
}
OUTPUT_CONFIGS = {
"save_checkpoints": True,
"save_results": True,
"save_generated_programs": True,
"log_level": "INFO",
"progress_bar": True,
}
def get_default_config() -> Dict[str, Any]:
return {
"model": MODEL_CONFIGS["seq2seq"],
"training": TRAINING_CONFIGS,
"data": DATA_CONFIGS,
"task": TASK_CONFIGS["arithmetic"],
"evaluation": EVALUATION_CONFIGS,
"device": DEVICE_CONFIGS,
"output": OUTPUT_CONFIGS,
}
def get_model_config(model_type: str) -> Dict[str, Any]:
if model_type not in MODEL_CONFIGS:
raise ValueError(f"Unknown model type: {model_type}")
return MODEL_CONFIGS[model_type]
def get_task_config(task: str) -> Dict[str, Any]:
if task not in TASK_CONFIGS:
raise ValueError(f"Unknown task: {task}")
return TASK_CONFIGS[task]
def get_device() -> torch.device:
if DEVICE_CONFIGS["auto"]:
if torch.cuda.is_available() and DEVICE_CONFIGS["prefer_cuda"]:
return torch.device("cuda")
elif DEVICE_CONFIGS["fallback_cpu"]:
return torch.device("cpu")
return torch.device("cpu")
SPECIAL_TOKENS = {
"PAD": "<PAD>",
"BOS": "<BOS>",
"EOS": "<EOS>",
"UNK": "<UNK>",
}
SPECIAL_TOKEN_IDS = {
"PAD": 0,
"BOS": 1,
"EOS": 2,
"UNK": 3,
}
if __name__ == "__main__":
print("Default configuration:")
config = get_default_config()
for key, value in config.items():
print(f" {key}: {value}")
print(f"\nDevice: {get_device()}")
print(f"Special tokens: {SPECIAL_TOKENS}")

Xet Storage Details

Size:
4.48 kB
·
Xet hash:
9c436d2c21c23150a8afeaf6fa2d7478c5dcce697ed340dbf00236e2815b47f7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.