{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d2b361bf",
   "metadata": {},
   "source": [
    "Copyright (c) 2023 Graphcore Ltd. All rights reserved."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "0cf5b60d",
   "metadata": {},
   "source": [
    "> Refer to the guidelines section [Copyright notice](notebook_guidelines.md#copyright-notice) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "1847b0b2",
   "metadata": {},
   "source": [
    "# [Solution/Task] on IPUs using [Model] - Inference/Fine-tuning [optional where applicable, for example \"using your own dataset\"]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "fbed8a88",
   "metadata": {},
   "source": [
    "> Refer to the guidelines section [Notebook title](notebook_guidelines.md#notebook-title) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "c55cde82",
   "metadata": {},
   "source": [
    "> ## About this template\n",
    ">\n",
    "> This template is intended to be used in conjunction with the [Guidelines for Writing a Notebook](notebook_guidelines.md). \n",
    ">\n",
    "> This template contains the proposed structure for Graphcore notebooks. Details\n",
    "> about the content for each section or about writing notebooks are given in the\n",
    "> [guidelines](notebook_guidelines.md) notebook.\n",
    ">\n",
    "> This template covers both the structure of the notebook (sections) and standard\n",
    "> text for some sections. \n",
    ">\n",
    "> Sections (*including headings*) inside `>` quote blocks are the template\n",
    "> instructions. Once you have followed these instructions please delete the\n",
    "> quoted text."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "cab665fb",
   "metadata": {},
   "source": [
    "> ## Introduction\n",
    "> \n",
    "> Refer to the guidelines section [Introduction](notebook_guidelines.md#introduction) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "6b24da1d",
   "metadata": {},
   "source": [
    "> Refer to the guidelines section [Summary table](notebook_guidelines.md#summary-table) for more details.\n",
    "> This summary table is populated with an example, modify the cell contents to match your notebook."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "4d704c6b",
   "metadata": {},
   "source": [
    "|  Domain | Tasks | Model | Datasets | Workflow |   Number of IPUs   | Execution time |\n",
    "|---------|-------|-------|----------|----------|--------------|--------------|\n",
    "|   NLP   |  Q&A  | GPT-J | Glue-MNLI| Training, evaluation, inference | recommended: 16XX (min: 4X) | 20Xmin (X1h20min)   |"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "e3a3fb59",
   "metadata": {},
   "source": [
    "> The first paragraph of text should contain all the key information to help\n",
    "> users rapidly decide if this notebook can help them solve their problem. It\n",
    "> takes time to run a notebook and we don't want to waste a user's time. So, the\n",
    "> intro paragraph must be very clear about:\n",
    ">\n",
    "> - The task/business problem this demo presents a solution for\n",
    "> - The features that are used in the demo, focussing on big-picture deep\n",
    ">  learning features, for example distributed training and not I/O overlap.\n",
    ">  Remember, we are trying to solve a user's problem, not sell an IPU-specific\n",
    ">  feature.\n",
    ">\n",
    "> Refer to the guidelines section [Intro paragraph](notebook_guidelines.md#intro-paragraph) for more details.\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d8dc6944",
   "metadata": {},
   "source": [
    "In this notebook, we will cover the following:\n",
    "\n",
    "* [list the learning outcomes]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "d2fdf150",
   "metadata": {},
   "source": [
    "> Refer to the guidelines section [Learning outcomes](notebook_guidelines.md#learning-outcomes) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "bd1c0747",
   "metadata": {},
   "source": [
    "> Include links to other resources.\n",
    ">\n",
    "> Refer to the guidelines section [Links to other resources](notebook_guidelines.md#links-to-other-resources) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "5c334fed",
   "metadata": {},
   "source": [
    "[![Join our Slack Community](https://img.shields.io/badge/Slack-Join%20Graphcore's%20Community-blue?style=flat-square&logo=slack)](https://www.graphcore.ai/join-community)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0279f464",
   "metadata": {},
   "outputs": [],
   "source": [
    "# During development it can be very useful to make imported python\n",
    "# modules automatically reload when the files are changed\n",
    "# needs to be before the first import.\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "# TODO: remove at the end of notebook development"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db890f52",
   "metadata": {},
   "source": [
    "## Environment setup\n",
    "\n",
    "The best way to run this demo is on Paperspace Gradient’s cloud IPUs because everything is already set up for you. To improve your experience, we preload datasets and pre-install packages. This can take a few minutes. If you experience errors immediately after starting a session, please try restarting the kernel before contacting support. If a problem persists or you want to give us feedback on the content of this notebook, please reach out to through our community of developers using our [Slack channel](https://www.graphcore.ai/join-community) or raise a [GitHub issue](<link to GitHub repo>). \n",
    "\n",
    "\n",
    "To run the demo using other IPU hardware, you need to have the Poplar SDK enabled {and a PopTorch/TensorFlow wheel installed}. Refer to the [Getting Started guide](https://docs.graphcore.ai/en/latest/getting-started.html#getting-started) for your system for details on how to do this. Also refer to the [Jupyter Quick Start guide](https://docs.graphcore.ai/projects/jupyter-notebook-quick-start/en/latest/index.html) for how to set up Jupyter to be able to run this notebook on a remote IPU machine."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "f4201c70",
   "metadata": {},
   "source": [
    "> Refer to the guidelines sections [Environment setup](notebook_guidelines.md#environment-setup) for more details and [Link for the Run on Gradient button](notebook_guidelines.md#link-for-the-run-on-gradient-button)."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "fbe9927c",
   "metadata": {},
   "source": [
    "## Dependencies and configuration"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "52a5b949",
   "metadata": {},
   "source": [
    "> We include the installation of dependencies in this section because this is required irrespective of the platform used to run the notebook. Note: The \"Environment setup\" is removed for the Paperspace version of the notebooks, so having other dependencies separate makes this task easier.\n",
    ">\n",
    "> Refer to the guidelines section [Dependencies and configuration](notebook_guidelines.md#dependencies-and-configuration) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "41415b4a",
   "metadata": {},
   "source": [
    "Install the dependencies the notebook needs."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "7e1b58db",
   "metadata": {},
   "source": [
    "> Example code block"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78c567f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "!apt update -y\n",
    "!apt install -y <reqs...>\n",
    "# example running make:\n",
    "import os\n",
    "\n",
    "code_directory = os.getenv(\"OGB_SUBMISSION_CODE\", \".\")\n",
    "!cd {code_directory} && make -C data_utils/feature_generation\n",
    "!cd {code_directory} && make -C static_ops"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "3ac66327",
   "metadata": {},
   "source": [
    "> Example code block"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c72d24a",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install -r requirements.txt\n",
    "%load_ext graphcore_cloud_tools.notebook_logging.gc_logger"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "26bbc7a9",
   "metadata": {},
   "source": [
    "In order to improve usability and support for future users, Graphcore would like to collect information about the applications and code being run in this notebook. The following information will be anonymised before being sent to Graphcore:\n",
    "\n",
    "- User progression through the notebook\n",
    "- Notebook details: number of cells, code being run and the output of the cells\n",
    "- Environment details\n",
    "\n",
    "You can disable logging at any time by running `%unload_ext graphcore_cloud_tools.notebook_logging.gc_logger` from any cell."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "b33a842f",
   "metadata": {},
   "source": [
    "To make it easier for you to run this demo, we read in some configuration related to the environment you are running the notebook in."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "90570e74",
   "metadata": {},
   "source": [
    "> The cell below reads environment variables that you can use to customise the behaviour of your notebook, see the full list of environment variables in the `setup.sh` script of the `graphcore/Gradient-...` repositories. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "965ca0a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "# TODO: Delete any variable you do not use.\n",
    "number_of_ipus = int(os.getenv(\"NUM_AVAILABLE_IPU\", 16))\n",
    "pod_type = os.getenv(\"GRAPHCORE_POD_TYPE\", \"pod16\")\n",
    "executable_cache_dir = os.getenv(\"POPLAR_EXECUTABLE_CACHE_DIR\", \"/tmp/exe_cache/\")\n",
    "dataset_directory = os.getenv(\"DATASETS_DIR\")\n",
    "checkpoint_directory = os.getenv(\"CHECKPOINT_DIR\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "0a32779d",
   "metadata": {},
   "source": [
    "## Sub-section [as many as you need for the body of the notebook]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "6ed9e6a5",
   "metadata": {},
   "source": [
    "> You are free to structure the body of your notebook exactly as you wish. \n",
    ">\n",
    "> Use sub-sub-sections to further structure your content.\n",
    ">\n",
    "> Refer to the guidelines section [Main body of notebook](notebook_guidelines.md#main-body-of-notebook) for more details."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "7ece4041",
   "metadata": {},
   "source": [
    "## Conclusions and next steps"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "234f3167",
   "metadata": {},
   "source": [
    "> This section should describe what was achieved in this notebook and list some resources (other notebooks, tutorials, documentation) to get the user to continue using our product. \n",
    ">\n",
    "> Ideally this should repeat the items in the learning outcomes section, but being more specific about how the outcomes were addressed.\n",
    ">\n",
    "> Refer to the guidelines section [Conclusions and next steps](notebook_guidelines.md#conclusions-and-next-steps) for more details."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f99f80f",
   "metadata": {},
   "source": [
    "Try out the other [IPU-powered Jupyter Notebooks](https://www.graphcore.ai/ipu-jupyter-notebooks) to see how how IPUs perform on other tasks."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
