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
download_data('https://pl-flash-data.s3.amazonaws.com/imdb.zip', 'data/') |
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 pytorch_lightning import Trainer | |
from flash.core.data import download_data | |
from flash.text import TextClassificationData, TextClassifier |
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
! pip install lightning-flash |
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
class DataModule(pl.LightningDataModule): | |
def __init__(self, data_dir: str = PATH, batch_size): | |
# Initalize | |
def prepare_data(self): | |
# Download and Preprocess Raw Data to File System or In Memory | |
def setup(self, stage=None): | |
# Load, Transform and Split Data |
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
def forward(...): | |
embeddings = self.encoder(x) | |
def training_step(...): | |
x, y = ... | |
z = self.encoder(x) | |
pred = self.decoder(z) | |
... |
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
class LitModel(pl.LightningModule): | |
def __init__(self, encoder: nn.Module, coeff_x: float = 0.2, lr: float = 1e-3) |
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
import os | |
from azureml.core import ScriptRunConfig, Experiment | |
from azureml.core.runconfig import MpiConfiguration | |
cluster = ws.compute_targets[cluster_name] | |
src = ScriptRunConfig( | |
source_directory=source_dir, | |
script=script_name, | |
arguments=["--max_epochs", 5, "--gpus", 2, "--num_nodes", 2, "--accelerator", "ddp"], |
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
def set_environment_variables_for_nccl_backend(single_node=False, master_port=6105): | |
if not single_node: | |
master_node_params = os.environ["AZ_BATCH_MASTER_NODE"].split(":") | |
os.environ["MASTER_ADDR"] = master_node_params[0] | |
# Do not overwrite master port with that defined in AZ_BATCH_MASTER_NODE | |
if "MASTER_PORT" not in os.environ: | |
os.environ["MASTER_PORT"] = str(master_port) | |
else: | |
os.environ["MASTER_ADDR"] = os.environ["AZ_BATCHAI_MPI_MASTER_NODE"] |
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
import json | |
import time | |
import pandas as pd | |
from requests import get, post | |
def extract_value(value): | |
""" | |
Helper Method to Extract Cell Value from Response | |
""" | |
if value['type'] == 'number': |
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
########### Python Form Recognizer Async Analyze ############# | |
import json | |
import time | |
from requests import get, post | |
# Endpoint URL | |
endpoint = r"<endpoint>" | |
apim_key = "<subsription key>" | |
model_id = "<model_id>" | |
post_url = endpoint + "/formrecognizer/v2.0-preview/custom/models/%s/analyze" % model_id |