You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 11, 2020. It is now read-only.
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):
74
75
75
76
1. You need to use a bare import statement, `import paperspace`, and not use the `import paperspace as ...` form.
76
77
2. The import form `from paperspace import ...` is currently not supported.
77
78
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.
78
79
4. Dependencies that are included before `paperspace.run()` must be available locally.
79
80
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)
81
82
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.
83
84
84
85
85
86
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
107
108
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.
108
109
109
110
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:
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:
127
130
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]`
130
132
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:
134
134
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`
137
136
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.
140
166
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:
143
178
144
179
paperspace-python run myscript.py --workspace .
145
180
146
181
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.
147
182
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:
149
184
150
185
paperspace-python run myscript.py --workspace . --ignoreFiles "hello.py,paperspace"
151
186
152
187
The following files and directories are ignored by default: `.git`, `.gitignore`, `__pycache__`.
153
188
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:
155
192
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>')
- `--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.
157
224
158
225
All of the above options can be combined in any combination, however, the order of operations is fixed to the following:
159
226
@@ -162,6 +229,8 @@ All of the above options can be combined in any combination, however, the order
162
229
3. `pip[2|3] install -r requirements.txt` is run if `--req <requirements.txt>` is specified
163
230
4. `python[2|3] myscript.py` is run
164
231
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.
0 commit comments