Skip to content

Commit

Permalink
Update train-model
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragjn committed Sep 9, 2024
1 parent dd69688 commit 907b604
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 50 deletions.
75 changes: 39 additions & 36 deletions train-model/Deploy_your_first_job.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,7 @@
"└── requirements.txt\n",
"```\n",
"\n",
"As you can see, all the following files are created in the same folder/directory\n",
"\n",
"**Let's create the directory which will contain all this files:-**\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WNso7zEy6UfI",
"outputId": "0a1b934c-65b6-490f-c672-e10bee256f19"
},
"outputs": [],
"source": [
"%mkdir develop\n",
"%cd develop"
"As you can see, all the following files are created in the same folder/directory\n"
]
},
{
Expand Down Expand Up @@ -136,7 +118,18 @@
"\n",
"Once you run the cell below you will get a prompt to enter your Workspace FQN. Follow the docs to\n",
"\n",
"**Create a Workspace**: https://docs.truefoundry.com/docs/key-concepts#creating-a-workspace "
"**Create a Workspace**: https://docs.truefoundry.com/docs/key-concepts#creating-a-workspace\n",
"\n",
"**Get Existing Workspace FQN**: https://docs.truefoundry.com/docs/key-concepts#getting-workspace-fqn"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import click"
]
},
{
Expand All @@ -147,7 +140,11 @@
},
"outputs": [],
"source": [
"WORKSPACE_FQN = input(\"Enter your Workspace FQN: \")"
"WORKSPACE_FQN = click.prompt(\n",
" \"Enter the Workspace FQN\",\n",
" type=str,\n",
")\n",
"print(f\"\\nWorkspace FQN set to {WORKSPACE_FQN!r}\")"
]
},
{
Expand Down Expand Up @@ -298,25 +295,24 @@
"\n",
"from truefoundry.deploy import Build, Job, PythonBuild, LocalSource\n",
"\n",
"logging.basicConfig(level=logging.INFO)\n",
"logging.basicConfig(\n",
" level=logging.INFO, format=\"%(asctime)s [%(name)s] %(levelname)-8s %(message)s\"\n",
")\n",
"\n",
"parser = argparse.ArgumentParser()\n",
"parser.add_argument(\"--workspace_fqn\", required=True, type=str)\n",
"args = parser.parse_args()\n",
"\n",
"# First we define how to build our code into a Docker image\n",
"image = Build(\n",
" build_source=LocalSource(local_build=False),\n",
" build_spec=PythonBuild(\n",
" python_version=\"3.11\",\n",
" command=\"python train.py\",\n",
" requirements_path=\"requirements.txt\",\n",
" )\n",
")\n",
"\n",
"job = Job(\n",
" name=\"iris-train-job\",\n",
" image=image\n",
" image=Build(\n",
" build_source=LocalSource(local_build=False),\n",
" build_spec=PythonBuild(\n",
" python_version=\"3.11\",\n",
" command=\"python train.py\",\n",
" requirements_path=\"requirements.txt\",\n",
" )\n",
" )\n",
")\n",
"job.deploy(workspace_fqn=args.workspace_fqn, wait=False)"
]
Expand Down Expand Up @@ -353,16 +349,23 @@
"source": [
"!python deploy.py --workspace_fqn $WORKSPACE_FQN"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "jupyter-base",
"language": "python",
"name": "python3"
"name": "jupyter-base"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -374,7 +377,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
22 changes: 11 additions & 11 deletions train-model/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

from truefoundry.deploy import Build, Job, LocalSource, PythonBuild

logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(name)s] %(levelname)-8s %(message)s")

parser = argparse.ArgumentParser()
parser.add_argument("--workspace_fqn", required=True, type=str)
args = parser.parse_args()

# First we define how to build our code into a Docker image
image = Build(
build_source=LocalSource(local_build=False),
build_spec=PythonBuild(
python_version="3.11",
command="python train.py",
requirements_path="requirements.txt",
job = Job(
name="iris-train-job",
image=Build(
build_source=LocalSource(local_build=False),
build_spec=PythonBuild(
python_version="3.11",
command="python train.py",
requirements_path="requirements.txt",
),
),
)

job = Job(name="iris-train-job", image=image)
job.deploy(workspace_fqn=args.workspace, wait=False)
job.deploy(workspace_fqn=args.workspace_fqn, wait=False)
5 changes: 2 additions & 3 deletions train-model/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
numpy>=1.23.2,<2.2.0
pandas>=1.5.3,<2.3.0
pandas==1.5.3
numpy==1.23.2
scikit-learn==1.5.0
truefoundry[ml]>=0.2.0,<1.0.0
2 changes: 2 additions & 0 deletions train-model/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split

# load the dataset
X, y = load_iris(as_frame=True, return_X_y=True)
X = X.rename(
columns={
Expand All @@ -16,6 +17,7 @@
# NOTE:- You can pass these configurations via command line
# arguments, config file, environment variables.
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)

# Initialize the model
clf = LogisticRegression(solver="liblinear")
# Fit the model
Expand Down

0 comments on commit 907b604

Please sign in to comment.