บทความนี้อธิบายการใช้งานโปรแกรม Apptainer สำหรับการรัน Training บนระบบ LANTA โดยหัวข้อต่อไปนี้ให้ข้อมูลสรุปเนื้อหาของบทความ เพื่อให้ผู้อ่านสามารถระบุส่วนที่ต้องการอ่านได้อย่างรวดเร็ว
การดาวน์โหลดไฟล์ Container ของ Tensorflow
ตรวจสอบ
ใช้คำสั่ง apptiner pull
username@lanta:~> apptainer pull tensorflow.sif docker://tensorflow/tensorflow:latest
Script.py
# this code is taken from https://www.tensorflow.org/tutorials/keras/classification # the code was modified to using pre-downloaded data instead of downloading from the API. # Tensorflow version 2.3.1 import tensorflow as tf import numpy as np fashion_mnist = tf.keras.datasets.fashion_mnist #(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() with open('mnist_data.npy', 'rb') as f: train_images = np.load(f) train_labels = np.load(f) test_images = np.load(f) test_labels = np.load(f) class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot'] # Explore Data train_images.shape len(train_labels) test_images.shape len(test_labels) # Preprocess Data train_images = train_images / 255.0 test_images = test_images / 255.0 tf.debugging.set_log_device_placement(True) strategy = tf.distribute.MirroredStrategy() with strategy.scope() : model = tf.keras.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dense(10) ]) model.compile(optimizer='adam', loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=['accuracy']) model.fit(train_images, train_labels, epochs=10) test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2) print('\n Test loss:', test_loss) print('\nTest accuracy:', test_acc) # MIT License # # Copyright (c) 2017 François Chollet # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE.
Scritp.sh
#!/bin/bash #SBATCH -p gpu # Specify the partition or machine type used [Compute/Memory/GPU] #SBATCH -N 1 --ntasks-per-node=40 # Specify the number of nodes and the number of core per node #SBATCH -t 00:30:00 # Specifies the maximum time limit (hour: minute: second) #SBATCH -J SIN101 # Specify the name of the Job #SBATCH -A train001 # Specify Project account which will be received after Register ** If you do not specify in this section, the job will not be able to run. #SBATCH # You can specify additional options. module purge # unload all modules as they may have previously been loaded. module load Singularity # Load the module that you want to use. singularity exec --nv tensorflow_2.3.1-gpu.sif python mnist.py # Run your program or executable code
การส่ง Job
sbatch submit.sh