-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: gpu: add a basic tensorflow test
Signed-off-by: Tuomas Katila <[email protected]>
- Loading branch information
Showing
4 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: training-pod | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: testcontainer | ||
image: intel/intel-extension-for-tensorflow:1.1.0-gpu-flex | ||
imagePullPolicy: IfNotPresent | ||
command: ["/bin/sh", "-c"] | ||
args: ["python /code/training.py"] | ||
resources: | ||
limits: | ||
gpu.intel.com/i915: 1 | ||
requests: | ||
gpu.intel.com/i915: 1 | ||
volumeMounts: | ||
- mountPath: /code | ||
name: code | ||
volumes: | ||
- configMap: | ||
name: training-code | ||
name: code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
configMapGenerator: | ||
- name: training-code | ||
files: | ||
- training.py | ||
|
||
resources: | ||
- deployment.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# original code from: | ||
# https://github.com/tensorflow/examples/blob/master/courses/udacity_intro_to_tensorflow_for_deep_learning/l02c01_celsius_to_fahrenheit.ipynb | ||
# this is slightly modified to run explicitly with XPU devices | ||
|
||
import tensorflow as tf | ||
import intel_extension_for_tensorflow as itex | ||
import numpy as np | ||
|
||
print("BACKENDS: ", str(itex.get_backend())) | ||
|
||
devs = tf.config.list_physical_devices('XPU') | ||
|
||
print(devs) | ||
|
||
if not devs: | ||
raise Exception("No devices found") | ||
|
||
with tf.device("/xpu:0"): | ||
celsius_q = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) | ||
fahrenheit_a = np.array([-40, 14, 32, 46, 59, 72, 100], dtype=float) | ||
|
||
model = tf.keras.Sequential([ | ||
tf.keras.layers.Dense(units=1, input_shape=[1]) | ||
]) | ||
|
||
model.compile(loss='mean_squared_error', | ||
optimizer=tf.keras.optimizers.Adam(0.1)) | ||
|
||
history = model.fit(celsius_q, fahrenheit_a, epochs=500, verbose=False) | ||
|
||
print("model trained") | ||
|
||
test = [100.0] | ||
p = model.predict(test) | ||
|
||
if len(p) != 1: | ||
raise Exception("invalid result obj") | ||
|
||
prediction = p[0] | ||
|
||
if prediction >= 211 and prediction <= 213: | ||
print("inference ok: %f" % prediction) | ||
else: | ||
raise Exception("bad prediction %f" % prediction) | ||
|
||
print("SUCCESS") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters