Skip to main content

Submit PrimeHub jobs easier

Project description

This is still in the Pre-Alpha stage.

PrimeHub Job

Submit PrimeHub jobs easier

Install

pip install primehub_job

How to Use

  1. PrimeHub version >= 2.8
  2. Set the API_TOKEN environment variable
  3. Make sure your group have group volume
from primehub_job import submit_phjob, get_phjob_logs, get_phjob_result, wait_and_get_phjob_result

# You can write @submit_job() to use default settings.
@submit_phjob(name='submitJob', image='datascience-notebook', instance_type='cpu')
def test(a, b='b'):
    print(a)
    print(b)
    return a, b

# Submit a job and wait the result
wait_and_get_phjob_result(test('aaa', 'ccc'))

# Submit a job
job_id = test('aaa', 'ccc')
# Get the running logs
print(get_phjob_logs(job_id))
# Get the job result
get_phjob_result(job_id)

Restrictions

  1. Don't use global variables in functions
  2. If you want to return a model, please use the framework's saver to save model, and return the saved model path to load the model. Here is the example:
# tensorflow
def export_model(model, export_path):
    if os.path.isdir(export_path):
        print('Cleaning up\n')
        shutil.rmtree(export_path)

    model.save(export_path)
    return export_path

@submit_phjob()
def training(epochs=2, dropout=0.2):
    mnist = tf.keras.datasets.mnist

    (x_train, y_train),(x_test, y_test) = mnist.load_data()
    x_train, x_test = x_train / 255.0, x_test / 255.0

    model = tf.keras.models.Sequential([
      tf.keras.layers.Flatten(input_shape=(28, 28)),
      tf.keras.layers.Dense(512, activation=tf.nn.relu),
      tf.keras.layers.Dropout(dropout),
      tf.keras.layers.Dense(10, activation=tf.nn.softmax)
    ])

    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])

    model.fit(x_train, y_train, epochs=epochs)
    model.evaluate(x_test, y_test)

    return export_model(model, '1')

job_id = training()

# load trained model
model = tf.keras.models.load_model(get_phjob_folder_path(job_id) + '/' + wait_and_get_phjob_result(job_id))

Run the Tests

python -m pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

primehub_job-0.0.12.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

primehub_job-0.0.12-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file primehub_job-0.0.12.tar.gz.

File metadata

  • Download URL: primehub_job-0.0.12.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for primehub_job-0.0.12.tar.gz
Algorithm Hash digest
SHA256 9668b62beaa8f44c5167224fef8b7e4ff971caf584d6c465d5c0560a35fd8784
MD5 92a6d64e26b4472a105a004b5f1c6d01
BLAKE2b-256 23f7aead5368d921ebed9243f50247afc260276eb3f379b2057ee2d69dc92052

See more details on using hashes here.

File details

Details for the file primehub_job-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: primehub_job-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for primehub_job-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 438218ddc7944f5cd0d107f4aaee39bef4c6e1de2caece0acbfb4ca2e4c1ba63
MD5 da0b3223bacfe87f97a180eff460ef40
BLAKE2b-256 90c31ad2db3e3aa49f7b94497774f364bf4fab2048fe1d16e3c2a1acbf7a256d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page