Spaces:
Runtime error
Runtime error
stakelovelace
commited on
Commit
·
339b8e7
1
Parent(s):
457f3a4
commit from tesla
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ def load_data_and_config(data_path):
|
|
| 33 |
|
| 34 |
def train_model(model, tokenizer, data, device):
|
| 35 |
"""Trains the model using the Hugging Face Trainer API."""
|
| 36 |
-
inputs = [tokenizer(d['text'], max_length=
|
| 37 |
dataset = Dataset.from_dict({
|
| 38 |
'input_ids': [x['input_ids'].squeeze() for x in inputs],
|
| 39 |
'labels': [x['input_ids'].squeeze() for x in inputs]
|
|
@@ -42,9 +42,9 @@ def train_model(model, tokenizer, data, device):
|
|
| 42 |
training_args = TrainingArguments(
|
| 43 |
output_dir='./results',
|
| 44 |
num_train_epochs=3,
|
| 45 |
-
per_device_train_batch_size=
|
| 46 |
-
gradient_accumulation_steps=
|
| 47 |
-
fp16=True, # Enable mixed precision
|
| 48 |
warmup_steps=500,
|
| 49 |
weight_decay=0.01,
|
| 50 |
logging_dir='./logs',
|
|
@@ -70,8 +70,9 @@ def main(api_name, base_url):
|
|
| 70 |
# Load the configuration for a specific model
|
| 71 |
config = AutoConfig.from_pretrained('google/codegemma-2b')
|
| 72 |
# Update the activation function
|
| 73 |
-
config.hidden_act = '
|
| 74 |
-
|
|
|
|
| 75 |
model = AutoModelForCausalLM.from_pretrained('google/codegemma-2b', is_decoder=True)
|
| 76 |
#model = BertLMHeadModel.from_pretrained('google/codegemma-2b', is_decoder=True)
|
| 77 |
# Example assuming you have a prepared dataset for classification
|
|
|
|
| 33 |
|
| 34 |
def train_model(model, tokenizer, data, device):
|
| 35 |
"""Trains the model using the Hugging Face Trainer API."""
|
| 36 |
+
inputs = [tokenizer(d['text'], max_length=256, truncation=True, padding='max_length', return_tensors="pt") for d in data]
|
| 37 |
dataset = Dataset.from_dict({
|
| 38 |
'input_ids': [x['input_ids'].squeeze() for x in inputs],
|
| 39 |
'labels': [x['input_ids'].squeeze() for x in inputs]
|
|
|
|
| 42 |
training_args = TrainingArguments(
|
| 43 |
output_dir='./results',
|
| 44 |
num_train_epochs=3,
|
| 45 |
+
per_device_train_batch_size=1,
|
| 46 |
+
gradient_accumulation_steps=2,
|
| 47 |
+
# fp16=True, # Enable mixed precision
|
| 48 |
warmup_steps=500,
|
| 49 |
weight_decay=0.01,
|
| 50 |
logging_dir='./logs',
|
|
|
|
| 70 |
# Load the configuration for a specific model
|
| 71 |
config = AutoConfig.from_pretrained('google/codegemma-2b')
|
| 72 |
# Update the activation function
|
| 73 |
+
config.hidden_act = '' # Set to use approximate GeLU gelu_pytorch_tanh
|
| 74 |
+
config.hidden_activation = 'gelu' # Set to use GeLU
|
| 75 |
+
|
| 76 |
model = AutoModelForCausalLM.from_pretrained('google/codegemma-2b', is_decoder=True)
|
| 77 |
#model = BertLMHeadModel.from_pretrained('google/codegemma-2b', is_decoder=True)
|
| 78 |
# Example assuming you have a prepared dataset for classification
|