This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from autogen_core import CancellationToken | |
from pydantic import BaseModel | |
from autogen_core.models import ChatCompletionClient, CreateResult, SystemMessage, UserMessage, AssistantMessage | |
from autogen_core.tools import Tool | |
from llama_cpp import Llama | |
from typing import List, Dict, Any, Literal, Optional, Sequence, Union, AsyncGenerator | |
import json | |
class ComponentModel(BaseModel): | |
provider: str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export To Onnx | |
model.to_onnx(filepath, input_sample, export_params=True) | |
# Export to Torch Script | |
torch.jit.save(model.to_torchscript(), "model.pt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Trainer(num_gpus=32).predict(millions_of_reviews) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prediction = model.predict("This movie is great!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save Checkpoint | |
trainer.save_checkpoint("text_class_model.pt") | |
# Load Model From Checkpoint | |
model = TextClassifier.load_from_checkpoint("text_class_model.pt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trainer.test() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trainer = flash.Trainer(gpus=8) | |
trainer = flash.Trainer(gpus=8, num_nodes=32) | |
trainer = flash.Trainer(tpu_cores=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trainer = flash.Trainer(max_epochs = 1) | |
trainer.finetune(model, datamodule = datamodule) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = TextClassifier(num_classes = 2, backbone = 'roberta-base') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datamodule = TextClassificationData.from_files( | |
train_file="data/imdb/train.csv", | |
valid_file="data/imdb/valid.csv", | |
test_file="data/imdb/test.csv", | |
input="review", | |
target="sentiment" | |
) |
NewerOlder