Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 06532a2

Browse files
committed
update README
1 parent 6e1ac38 commit 06532a2

File tree

1 file changed

+103
-34
lines changed

1 file changed

+103
-34
lines changed

README.md

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Paperspace Python
22
=================
33

4-
Sample usage
5-
============
4+
Getting Started
5+
===============
66
1. Make sure you have a Paperspace account set up. Go to http://paperspace.com
77
to register.
88

@@ -31,7 +31,7 @@ Sample usage
3131

3232
`paperspace-python logout`
3333

34-
5. Execute the sample Python script hello.py:
34+
5. Run the sample script hello.py using Python:
3535

3636
`python hello.py`
3737

@@ -47,15 +47,16 @@ Sample usage
4747
4848
Note: the source is modified before transfer to the job cluster in order to remove imported `paperspace` references.
4949
50-
6. Execute an unmodified Python script remotely:
50+
6. Use paperspace-python to run a python script remotely:
5151
5252
`paperspace-python run myscript.py`
5353
5454
The script will be run on the Paperspace job cluster node, and its output will be logged locally.
5555
5656
57-
A slightly more complex example
58-
===============================
57+
Specifying jobs options within a script
58+
=======================================
59+
This example shows how a script can specify paperspace jobs options for itself, such as `project` name, `machineType`, and a `container` reference:
5960
6061
# tests/test_remote.py - runs itself on paperspace, demonstrates setting jobs create options
6162
import os
@@ -68,18 +69,18 @@ A slightly more complex example
6869
print('something useful')
6970
7071
71-
Automatic running of the current python script remotely
72-
=======================================================
73-
The above example demonstrate running a python script locally and having that script transmit itself to the paperspace jobs cluster for further execution. To do this a copy of the local script is modified before transmission to the jobs cluster, in order to strip out the `import paperspace` statements and other `paperspace` library references. There are also some limitations on the types of import statements that are supported, and the dependencies that are supported in each environment (local vs. remote):
72+
Automatic running of a python script remotely
73+
=============================================
74+
The above example demonstrates running a python script locally and having that script transmit itself to the paperspace jobs cluster for further execution. To do this a copy of the local script is modified before transmission to the jobs cluster, in order to strip out the `import paperspace` statements and other `paperspace` library references. There are also some limitations on the types of import statements that are supported, and the dependencies that are supported in each environment (local vs. remote):
7475
7576
1. You need to use a bare import statement, `import paperspace`, and not use the `import paperspace as ...` form.
7677
2. The import form `from paperspace import ...` is currently not supported.
7778
3. Everything after the `paperspace.run()` function call is ignored when running locally (when no script name is provided). The local script execution stops after the `paperspace.run()` call.
7879
4. Dependencies that are included before `paperspace.run()` must be available locally.
7980
5. If you need to reference dependencies that are not available locally but are available remotely, those should be imported after the `paperspace.run()` call.
80-
6. Dependencies that are needed remotely need to either be already installed in the container used for the job, or need to be installed using one of the techniques below in the section [Setting up python script dependencies remotely](#setting-up-python-script-dependencies-remotely)
81+
6. Dependencies that are needed remotely need to either be already installed in the container used for the job, or need to be installed using one of the techniques below in the section [Dependency Options](#dependency-options)
8182
82-
Because of these limitations it may not always be appropriate to run python scripts automatically from within the same script file. As an alternative you can run your python scripts unmodified using the techniques in the next section.
83+
Because of these limitations it may not always be appropriate to run python scripts automatically from within the same script file. As an alternative you can run your python scripts unmodified using the techniques below.
8384
8485
8586
Running a python script by name
@@ -107,53 +108,119 @@ In code you can provide additional paperspace jobs create options in a dict in t
107108
See the Paperspace API [jobs create](https://paperspace.github.io/paperspace-node/jobs.html#.create) documentation for the full list of jobs create options that can be specified.
108109
109110
110-
Setting up python script dependencies remotely
111-
==============================================
112-
When running python scripts on paperspace you may need to provide additional dependencies to your scripts.
113-
The `paperspace-python run` command and `paperspace.run()` function provide several options to support this:
111+
Using paperspace-python run
112+
===========================
113+
The `paperspace-python run` command provides a number of options to run python code and other commands remotely, as well as copy files and set up python dependencies:
114114
115-
paperspace-python run [-m] <python_script.py>
115+
paperspace-python run [options] [[-m] <script> [args] | -c "python code" | --command "shell cmd"]
116+
options:
116117
[--python 2|3]
117118
[--init [<init.sh>]]
118119
[--pipenv]
119120
[--req [<requirements.txt>]]
120121
[--workspace .|<workspace_path>]
121-
[--ignoreFiles "<file-or-dir>,<file-or-dir>,..."]
122-
[other jobs create options...]
122+
[--ignoreFiles "<file-or-dir>,..."]
123+
[jobs create options]
123124
[--dryrun]
124-
[script args]
125+
[-]
125126
126-
The `-m` option runs the specified library module as a script. This is equivalent to the `-m` option of the `python` executable.
127+
Basic Run Scenarios
128+
===================
129+
1. Run a python script remotely:
127130
128-
The `--python 2|3` option allows you specify whether to use `python2` or `python3` when running the script on paperspace.
129-
If ommitted, the script will be run with the same major version as is being used to run `paperspace-python` locally.
131+
`paperspace-python run <python_script.py> [args]`
130132
131-
The `--init [<init.sh>]` option is used to specify a script to be run on the remote machine, inside the container, before the python script is run.
132-
If the script name is ommitted, it is assumed to be the script named `init.sh` in the current directory. The script is run using
133-
`source init.sh` in the container bash shell. You can use this option to provide a list of commands to run to set up the dependencies for the script, such as running a list of `pip install` commands. However, if you are using `pipenv` or a `requirements.txt` file we recommend you use one of the options below. Multiple dependency setup options can be combinded however.
133+
Example:
134134
135-
The `--pipenv` option is used to upload and run the `Pipfile` and `Pipfile.lock` files in the current directory, if found. These files
136-
are used on the paperspace machine to initialize the python environment using the `pipenv` tool, by running `pipenv install` within the container. Note: `pipenv` must already be installed in the container for this option to work. The default container used by paperspace-python already has the `pipenv` package installed.
135+
`paperspace-python run myscript.py a b c`
137136
138-
The `--req [<requirements.txt>]` option is used specify that a `requirements.txt` file should be used to install the required python dependencies using `pip`.
139-
By default this option looks for a file named `requirements.txt` in the current directory, but you can override this by specifying a different file name. Note: `pip` must already be installed in the container for this option to work. The default container used by paperspace-python already has the `pip` package installed.
137+
2. Run a python module remotely using the `-m` option:
138+
139+
`paperspace-python run -m <module_path> [args]`
140+
141+
Example:
142+
143+
`paperspace-python run -m pip --version`
144+
145+
3. Run a python command remotely using the `-c` option:
146+
147+
`paperspace-python run -c "python_statement;..."`
148+
149+
Example:
150+
151+
`paperspace-python run -c "import os; print(os.getcwd())"`
152+
153+
4. Run an executable or shell command remotely using the `--command` option:
154+
155+
`paperspace-python run --command "<executable or shell command>"`
156+
157+
Example:
158+
159+
`paperspace-python run --command "ls -al"`
160+
161+
Run Options
162+
===========
163+
The `<script>` option is a python script or path to a python module. The script or module will be uploaded if it exists on the local file system.
164+
165+
Other script`args` can be provided after the python script or module path. You can use the `-` option to suppress interpretation of the list of script args as `paperspace-python run` options.
140166
141-
The jobs create `--workspace` option is also available with any or all of the above options.
142-
With the `--workspace` option you can specify a workspace directory to upload. For example, to upload the current directory along with the script file run:
167+
The `-m <module path>` option runs the specified library module as a script. This is equivalent to the `-m` option of the `python` executable. Further paperspace run option processing is disabled after the `-m` option.
168+
169+
The `-c "python_statement;..."` option runs the specified python statements. This is equivalent to the `-c` option of the `python` executable. Further paperspace run option processing is disabled after the `-c` option.
170+
171+
The `-` option disables further run command option processing and passes the remaining arguments to the script specified. This allows you to pass arguments to your script that might otherwise conflict with run command options or jobs create options.
172+
173+
The `--command "shell cmd"` option is used to run an arbitrary executable or shell command inside the container. Note: the executable or shell command must already be available inside the container image, or be copied over using the `--workspace` option.
174+
175+
Job Options
176+
===========
177+
The `--workspace` option allows you to specify a workspace file or directory to upload, or a git repo link to download and merge with the container. For example, to upload the current directory along with a script file run:
143178
144179
paperspace-python run myscript.py --workspace .
145180
146181
See the Paperspae API [jobs create](https://paperspace.github.io/paperspace-node/jobs.html#.create) documentation for more details on the `--workspace` option and related options.
147182
148-
The `--ignoreFiles "<file-or-dir>,<file-or-dir>,..."` option can be used specify a simple comma separated list of files and directories to ignore for the workspace upload:
183+
The `--ignoreFiles "<file-or-dir>,..."` option can be used specify a simple comma separated list of files and directories to ignore for the workspace upload:
149184
150185
paperspace-python run myscript.py --workspace . --ignoreFiles "hello.py,paperspace"
151186
152187
The following files and directories are ignored by default: `.git`, `.gitignore`, `__pycache__`.
153188
154-
The `--dryrun` option allows you to see the resultant script that will be run on the paperspace job runner without actually running it.
189+
Other `jobs create options` can be specified, such as `--machineType <machine type>`, `--container <container image reference>`, and `--project <project name>`.
190+
191+
Here are some of the other jobs create options available:
155192
156-
Finally, you can provide a trailing list of arguments to pass to the script.
193+
- `--project "<project name>"` (defaults to 'paperspace-python')
194+
- `--machineType [GPU+|P4000|P5000|P6000|V100]` (defaults to P5000)
195+
- `--container <docker image link or paperspace container name>` (defaults to `docker.io/paperspace/tensorflow-python`)
196+
- `--name "<job name>"` (defaults to 'job for project <project name>')
197+
- `--projectId "<existing paperspace project id>"`
198+
- `--registryUsername "<username>"` (for access to a private docker registry)
199+
- `--registryPassword "<secretpw>"` (for access to a private docker registry)
200+
- `--workspaceUsername "<username>"` (for access to a private git repo)
201+
- `--workspacePassword "<secretpw>"` (for access to a private git repo)
202+
203+
See the Paperspae API [jobs create](https://paperspace.github.io/paperspace-node/jobs.html#.create) documentation for a complete description of these options.
204+
205+
Dependency Options
206+
==================
207+
When running python scripts on paperspace you may need to provide additional dependencies to your scripts or specify the python version.
208+
The `paperspace-python run` command has several options to support this: `--python`, `--init`, `--pipenv`, and `--req`. In addition you can use the `--workspace` option above to upload file dependencies.
209+
210+
The `--python 2|3` option allows you specify whether to use `python2` or `python3` when running the script on paperspace.
211+
If ommitted, the script will be run with the same major version as is being used to run `paperspace-python` locally.
212+
213+
The `--init [<init.sh>]` option is used to specify a script to be run on the remote machine, inside the container, before the python script is run.
214+
If the init script name is ommitted, it is assumed to be the script named `init.sh` in the current directory. The script is run using
215+
`source init.sh` in the container bash shell. You can use this option to provide a list of commands to run to set up the dependencies for the script, such as running a list of `pip install` commands. However, if you are using `pipenv` or a `requirements.txt` file we recommend you use one of the options below. Multiple dependency setup options can be combinded however.
216+
217+
The `--pipenv` option is used to upload and run the `Pipfile` and `Pipfile.lock` files in the current directory, if found. These files
218+
are used on the paperspace machine to initialize the python environment using the `pipenv` tool, by running `pipenv install` within the container. Note: `pipenv` must already be installed in the container for this option to work. The default container used by paperspace-python already has the `pipenv` package installed.
219+
220+
The `--req [<requirements.txt>]` option is used specify that a `requirements.txt` file should be used to install the required python dependencies using `pip`.
221+
By default this option looks for a file named `requirements.txt` in the current directory, but you can override this by specifying a different file name. Note: `pip` must already be installed in the container for this option to work. The default container used by paperspace-python already has the `pip` package installed.
222+
223+
The `--dryrun` option allows you to see the resultant script that will be run on the paperspace job runner without actually running it.
157224
158225
All of the above options can be combined in any combination, however, the order of operations is fixed to the following:
159226
@@ -162,6 +229,8 @@ All of the above options can be combined in any combination, however, the order
162229
3. `pip[2|3] install -r requirements.txt` is run if `--req <requirements.txt>` is specified
163230
4. `python[2|3] myscript.py` is run
164231
232+
As mentioned above, you can use the `--dryrun` option to see the resultant commands that will be run on the paperspace jobs cluster node for a given set of options, without actually running the commands.
233+
165234
166235
Default Container
167236
=================

0 commit comments

Comments
 (0)