Soham Jain commited on
Initial commit of GPT-2 46M SwiGLU Dense baseline model architecture and configs
Browse files- configuration_gpt2.py +6 -2
- modeling_gpt2.py +4 -4
- train.py +2 -2
configuration_gpt2.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
from transformers import PretrainedConfig
|
| 2 |
|
| 3 |
-
class
|
| 4 |
-
model_type = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def __init__(
|
| 7 |
self,
|
|
|
|
| 1 |
from transformers import PretrainedConfig
|
| 2 |
|
| 3 |
+
class GPT2CustomConfig(PretrainedConfig):
|
| 4 |
+
model_type = "gpt2_custom"
|
| 5 |
+
auto_map = {
|
| 6 |
+
"AutoConfig": "configuration_gpt2.GPT2CustomConfig",
|
| 7 |
+
"AutoModelForCausalLM": "modeling_gpt2.GPT2CustomLMHeadModel"
|
| 8 |
+
}
|
| 9 |
|
| 10 |
def __init__(
|
| 11 |
self,
|
modeling_gpt2.py
CHANGED
|
@@ -4,7 +4,7 @@ import torch
|
|
| 4 |
import torch.nn as nn
|
| 5 |
import torch.nn.functional as F
|
| 6 |
from transformers import PreTrainedModel, GenerationMixin, AutoConfig, AutoModelForCausalLM
|
| 7 |
-
from configuration_gpt2 import
|
| 8 |
|
| 9 |
class CausalSelfAttention(nn.Module):
|
| 10 |
def __init__(self, config):
|
|
@@ -62,7 +62,7 @@ class GPT2Block(nn.Module):
|
|
| 62 |
return x
|
| 63 |
|
| 64 |
class GPT2CustomLMHeadModel(PreTrainedModel, GenerationMixin):
|
| 65 |
-
config_class =
|
| 66 |
base_model_prefix = "transformer"
|
| 67 |
|
| 68 |
def __init__(self, config):
|
|
@@ -114,5 +114,5 @@ class GPT2CustomLMHeadModel(PreTrainedModel, GenerationMixin):
|
|
| 114 |
return {"input_ids": input_ids}
|
| 115 |
|
| 116 |
# Register configuration and model for auto mapping
|
| 117 |
-
AutoConfig.register("
|
| 118 |
-
AutoModelForCausalLM.register(
|
|
|
|
| 4 |
import torch.nn as nn
|
| 5 |
import torch.nn.functional as F
|
| 6 |
from transformers import PreTrainedModel, GenerationMixin, AutoConfig, AutoModelForCausalLM
|
| 7 |
+
from configuration_gpt2 import GPT2CustomConfig
|
| 8 |
|
| 9 |
class CausalSelfAttention(nn.Module):
|
| 10 |
def __init__(self, config):
|
|
|
|
| 62 |
return x
|
| 63 |
|
| 64 |
class GPT2CustomLMHeadModel(PreTrainedModel, GenerationMixin):
|
| 65 |
+
config_class = GPT2CustomConfig
|
| 66 |
base_model_prefix = "transformer"
|
| 67 |
|
| 68 |
def __init__(self, config):
|
|
|
|
| 114 |
return {"input_ids": input_ids}
|
| 115 |
|
| 116 |
# Register configuration and model for auto mapping
|
| 117 |
+
AutoConfig.register("gpt2_custom", GPT2CustomConfig)
|
| 118 |
+
AutoModelForCausalLM.register(GPT2CustomConfig, GPT2CustomLMHeadModel)
|
train.py
CHANGED
|
@@ -75,7 +75,7 @@ def run_pipeline(model_name: str, epochs: int = 10, skip_eval: bool = False, ski
|
|
| 75 |
|
| 76 |
# Import model architecture
|
| 77 |
from modeling_gpt2 import GPT2CustomLMHeadModel
|
| 78 |
-
from configuration_gpt2 import
|
| 79 |
|
| 80 |
# Print GPU details
|
| 81 |
if torch.cuda.is_available():
|
|
@@ -232,7 +232,7 @@ def run_pipeline(model_name: str, epochs: int = 10, skip_eval: bool = False, ski
|
|
| 232 |
steps_per_epoch = chunks_per_epoch // GRAD_ACCUM_STEPS
|
| 233 |
total_steps = steps_per_epoch * EPOCHS
|
| 234 |
|
| 235 |
-
cfg =
|
| 236 |
vocab_size=VOCAB_SIZE,
|
| 237 |
n_positions=BLOCK_SIZE,
|
| 238 |
n_embd=768,
|
|
|
|
| 75 |
|
| 76 |
# Import model architecture
|
| 77 |
from modeling_gpt2 import GPT2CustomLMHeadModel
|
| 78 |
+
from configuration_gpt2 import GPT2CustomConfig
|
| 79 |
|
| 80 |
# Print GPU details
|
| 81 |
if torch.cuda.is_available():
|
|
|
|
| 232 |
steps_per_epoch = chunks_per_epoch // GRAD_ACCUM_STEPS
|
| 233 |
total_steps = steps_per_epoch * EPOCHS
|
| 234 |
|
| 235 |
+
cfg = GPT2CustomConfig(
|
| 236 |
vocab_size=VOCAB_SIZE,
|
| 237 |
n_positions=BLOCK_SIZE,
|
| 238 |
n_embd=768,
|