Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into feat/detect
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikb11 authored Feb 5, 2021
2 parents a7d0d4f + aeb0063 commit 5204570
Show file tree
Hide file tree
Showing 72 changed files with 1,125 additions and 478 deletions.
58 changes: 58 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

pull_request_rules:

- name: warn on conflicts
conditions:
- conflict
- -draft # filter-out GH draft PRs
- -label="has conflicts"
actions:
# comment:
# message: This pull request is now in conflict... :(
label:
add: [ "has conflicts" ]

- name: resolved conflicts
conditions:
- -conflict
- label="has conflicts"
- -draft # filter-out GH draft PRs
- -merged # not merged yet
- -closed
actions:
label:
remove: [ "has conflicts" ]

- name: update PR
conditions:
- -conflict
- -draft # filter-out GH draft PRs
- base=master # apply only on master
- -title~=(?i)wip # skip all PR that title contains “WIP” (ignoring case)
- "#approved-reviews-by>=2" # number of review approvals
actions:
update: {}

- name: add core reviewer
conditions:
- -conflict # skip if conflict
- -draft # filter-out GH draft PRs
- "#approved-reviews-by<2" # number of review approvals
- "#review-requested<1" # number of requested reviews
actions:
request_reviews:
teams:
- "@PyTorchLightning/core-contributors"
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
staleLabel: "won't fix"
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.lock
lightning_logs

# Byte-compiled / optimized / DLL files
Expand Down
12 changes: 0 additions & 12 deletions .run_local_tests.sh

This file was deleted.

28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.PHONY: test clean docs

# assume you have installed need packages
export SPHINX_MOCK_REQUIREMENTS=1

test: clean
pip install -r requirements.txt
pip install -r requirements/test.txt
# install APEX, see https://github.com/NVIDIA/apex#linux

# use this to run tests
python -m coverage run --source flash -m pytest flash tests -v --flake8
python -m coverage report

docs: clean
pip install --quiet -r requirements/docs.txt
python -m sphinx -b html -W docs/source docs/build

clean:
rm -rf _ckpt_*
rm -rf ./lightning_logs
# clean all temp runs
rm -rf $(shell find . -name "mlruns")
rm -rf .mypy_cache
rm -rf .pytest_cache
rm -rf ./docs/build
rm -rf ./docs/source/**/generated
rm -rf ./docs/source/api
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,35 @@

</div>

---
## News
[Read our launch blogpost](https://pytorch-lightning.medium.com/introducing-lightning-flash-the-fastest-way-to-get-started-with-deep-learning-202f196b3b98)

---

## Installation

Pip / conda

```bash
pip install lightning-flash
pip install lightning-flash -U
```

Master
Pip from source

```bash
pip install git+https://github.com/PytorchLightning/lightning-flash.git@master --upgrade
# with git
pip install git+https://github.com/PytorchLightning/lightning-flash.git@master
# OR from an archive
pip install https://github.com/PyTorchLightning/lightning-flash/archive/master.zip
```

Source

From source using `setuptools`
``` bash
# clone flash repository locally
git clone https://github.com/PyTorchLightning/lightning-flash.git
cd lightning-flash
# install in editable mode
pip install -e .
```

Expand Down Expand Up @@ -383,6 +392,9 @@ Join our [Slack](https://join.slack.com/t/pytorch-lightning/shared_invite/zt-f6b
## Community
For help or questions, join our huge community on [Slack](https://join.slack.com/t/pytorch-lightning/shared_invite/zt-f6bl2l0l-JYMK3tbAgAmGRrlNr00f1A)!

## Citations
We’re excited to continue the strong legacy of opensource software and have been inspired over the years by Caffee, Theano, Keras, PyTorch, torchbearer, and fast.ai. When/if a paper is written about this, we’ll be happy to cite these frameworks and the corresponding authors.

## License
Please observe the Apache 2.0 license that is listed in this repository. In addition
the Lightning framework is Patent Pending.
8 changes: 8 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,11 @@ def _package_list_from_file(pfile):
MOCK_PACKAGES = [PACKAGE_MAPPING.get(pkg, pkg) for pkg in MOCK_PACKAGES]

autodoc_mock_imports = MOCK_PACKAGES

# only run doctests marked with a ".. doctest::" directive
doctest_test_doctest_blocks = ''
doctest_global_setup = """
import torch
import pytorch_lightning as pl
import flash
"""
6 changes: 3 additions & 3 deletions docs/source/custom_task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tutorial: Creating a Custom Task
In this tutorial we will go over the process of creating a custom task,
along with a custom data module.

.. code:: python
.. testcode:: python

import flash

Expand All @@ -21,7 +21,7 @@ Here we create a basic linear regression task by subclassing
``flash.Task``. For the majority of tasks, you will likely only need to
override the ``__init__`` and ``forward`` methods.

.. code:: python
.. testcode::

class LinearRegression(flash.Task):
def __init__(self, num_inputs, learning_rate=0.001, metrics=None):
Expand Down Expand Up @@ -67,7 +67,7 @@ for the prediction of diabetes disease progression. We can create this
``DataModule`` below, wrapping the scikit-learn `Diabetes
dataset <https://scikit-learn.org/stable/datasets/toy_dataset.html#diabetes-dataset>`__.

.. code:: python
.. testcode::

class DiabetesPipeline(flash.core.data.TaskDataPipeline):
def after_uncollate(self, samples):
Expand Down
6 changes: 2 additions & 4 deletions docs/source/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ Flash is tested on Python 3.6+, and PyTorch 1.6
## Install with pip/conda

```bash
pip install lightning-flash
pip install lightning-flash -U
```

## Install from source

``` bash
git clone https://github.com/PyTorchLightning/flash.git
cd flash
pip install -e .
pip install git+https://github.com/PyTorchLightning/lightning-flash.git
```
6 changes: 4 additions & 2 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ organized PyTorch with the unecessary engineering details abstracted away.

When you need more flexibility you can build your own tasks or simply use Lightning directly.

.. note:: Read :doc:`here <reference/flash_to_pl>` to understand when to use Flash vs Lightning.
.. tip::

Read :doc:`here <reference/flash_to_pl>` to understand when to use Flash vs Lightning.

----

Expand All @@ -56,7 +58,7 @@ You can install flash using pip or conda:

.. code-block:: bash
pip install pytorch-lightning-flash -U -pre
pip install pytorch-lightning-flash -U
------

Expand Down
4 changes: 3 additions & 1 deletion docs/source/reference/image_classification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ Changing the backbone
*********************
By default, we use a `ResNet-18 <https://arxiv.org/abs/1512.03385>`_ for image classification. You can change the model run by the task by passing in a different backbone.

.. note:: When changing the backbone, make sure you pass in the same backbone to the Task and the Data object!
.. note::

When changing the backbone, make sure you pass in the same backbone to the Task and the Data object!

.. code-block:: python
Expand Down
10 changes: 5 additions & 5 deletions docs/source/reference/image_embedder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Or on a random image tensor

.. code-block:: python
# 2. Perform inference on an image file
import torch
images = torch.rand(32, 3, 224, 224)
embeddings = model.predict(images)
print(predictions)
# 2. Perform inference on an image file
import torch
images = torch.rand(32, 3, 224, 224)
embeddings = model.predict(images)
print(predictions)
For more advanced inference options, see :ref:`predictions`.

Expand Down
6 changes: 3 additions & 3 deletions docs/source/reference/summarization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ API reference
SummarizationTask
-----------------

.. autoclass:: flash.text.seq2seq.summarization.model.SummarizationTask
.. autoclass:: flash.text.SummarizationTask
:members:
:exclude-members: forward

Expand All @@ -180,6 +180,6 @@ SummarizationTask
SummarizationData
-----------------

.. autoclass:: flash.text.seq2seq.summarization.data.SummarizationData
.. autoclass:: flash.text.SummarizationData

.. automethod:: flash.text.seq2seq.summarization.data.SummarizationData.from_files
.. automethod:: flash.text.SummarizationData.from_files
4 changes: 1 addition & 3 deletions docs/source/reference/tabular_classification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ We can create :class:`~flash.tabular.TabularData` from csv files using the :func
* **numerical_input**- a list of the names of columns that contain numerical continuous data (floats)
* **target**- the name of the column we want to predict

.. tip:: you can pass in val_size and test_size to partition your training data into a separate validation and test set like so:


Next, we create the :class:`~flash.tabular.TabularClassifier` task, using the Data module we created.

.. code-block::
.. code-block:: python
import flash
from flash import download_data
Expand Down
14 changes: 7 additions & 7 deletions docs/source/reference/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Translation
###########

********
The task
The Task
********

Translation is the task of translating text from a source language to another, such as English to Romanian.
Expand All @@ -17,7 +17,7 @@ This task is a subset of Sequence to Sequence tasks, which requires the model to
Inference
*********

The :class:`~flash.text.TranslationTask` is already pre-trained on [WMT16 English/Romanian](https://www.statmt.org/wmt16/translation-task.html), a dataset of English to Romanian samples, based on the Europarl corpora.
The :class:`~flash.text.TranslationTask` is already pre-trained on `WMT16 English/Romanian <https://www.statmt.org/wmt16/translation-task.html>`_, a dataset of English to Romanian samples, based on the `Europarl corpora <http://www.statmt.org/europarl/>`_.

Use the :class:`~flash.text.TranslationTask` pretrained model for inference on any string sequence using :func:`~flash.text.TranslationTask.predict`:

Expand Down Expand Up @@ -78,7 +78,7 @@ Say you want to finetune to your own translation data. We use the English/Romani
In the above the input/target columns represent the English and Romanian translation respectively.

All we need is three lines of code to train our model!
All we need is three lines of code to train our model! By default, we use a `mBART <https://github.com/pytorch/fairseq/tree/master/examples/mbart/>`_ backbone for translation which requires a GPU to train.

.. code-block:: python
Expand Down Expand Up @@ -125,7 +125,7 @@ To run the example:
*********************
Changing the backbone
*********************
By default, we use `mBART <https://github.com/pytorch/fairseq/tree/master/examples/mbart/>`_ model for translation. You can change the model run by passing in the backbone parameter.
You can change the model run by passing in the backbone parameter.

.. note:: When changing the backbone, make sure you pass in the same backbone to the Task and the Data object! Since this is a Seq2Seq task, make sure you use a Seq2Seq model.

Expand Down Expand Up @@ -153,7 +153,7 @@ API reference
TranslationTask
---------------

.. autoclass:: flash.text.seq2seq.translation.model.TranslationTask
.. autoclass:: flash.text.TranslationTask
:members:
:exclude-members: forward

Expand All @@ -162,6 +162,6 @@ TranslationTask
TranslationData
---------------

.. autoclass:: flash.text.seq2seq.translation.data.TranslationData
.. autoclass:: flash.text.TranslationData

.. automethod:: flash.text.seq2seq.translation.data.TranslationData.from_files
.. automethod:: flash.text.TranslationData.from_files
1 change: 0 additions & 1 deletion flash/core/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Any, Union

import torch
from transformers.modeling_outputs import SequenceClassifierOutput

from flash.core.data import TaskDataPipeline
from flash.core.model import Task
Expand Down
23 changes: 18 additions & 5 deletions flash/core/data/datamodule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import warnings
import platform
from typing import Any, Optional

import pytorch_lightning as pl
Expand Down Expand Up @@ -51,11 +64,11 @@ def __init__(
self.batch_size = batch_size

# TODO: figure out best solution for setting num_workers
# if num_workers is None:
# num_workers = os.cpu_count()
if num_workers is None:
# warnings.warn("Could not infer cpu count automatically, setting it to zero")
num_workers = 0
if platform.system() == "Darwin":
num_workers = 0
else:
num_workers = os.cpu_count()
self.num_workers = num_workers

self._data_pipeline = None
Expand Down
Loading

0 comments on commit 5204570

Please sign in to comment.