-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Containerized Python Components #8353
Comments
Update I upgraded to I still see the behavior of To check that my non component python modules work I:
|
Hi, @statmike. Can you please provide the file tree that contains |
Having the same issue. Here are mine for a second look: my_component.pyfrom kfp import dsl @dsl.component( my_helper_module.pydef adding_stuff(x, y): |
Hello @connor-mccarthy , tree
init.py my_component.py # my_component.py
from kfp.v2 import dsl
import train
@dsl.component(
base_image = 'python:3.7',
target_image = 'us-central1-docker.pkg.dev/statmike-mlops-349915/statmike-mlops-349915/tips_kfp_kfp_component',
packages_to_install = ['numpy', 'scikit-learn']
)
def train_model(
size: int,
metrics: dsl.Output[dsl.Metrics],
class_metrics: dsl.Output[dsl.ClassificationMetrics]
):
# run
cm, auPRC = train.runner(size)
# output
metrics.log_metric('auPRC', auPRC)
class_metrics.log_confusion_matrix(['Not Fraud', 'Fraud'], cm) train.py # train.py
from sklearn import metrics
import my_helper
def runner(size):
# make data
x, y, p = my_helper.make_dataset(size)
# fit logistic regression
y_pred = my_helper.fit_logistic(x, y)
# gather metrics
cm = metrics.confusion_matrix(y, y_pred)
auPRC = metrics.accuracy_score(y, y_pred)
return cm, auPRC
cm, auPRC = runner(100) my_helper.py # my_helper.py
import numpy as np
from sklearn import linear_model
# Make some data where y = 0, 1 for a range of x's - let y=1 be more likely as x increases
def make_dataset(size):
x = np.random.randn(size)
p = 1 / (1 + np.exp(-1 * (5 * x)))
y = np.random.binomial(1, p, size)
return x, y, p
# fit logistic regression
def fit_logistic(x, y):
logisticReg = linear_model.LogisticRegression()
x2 = x.reshape(-1,1)
fit = logisticReg.fit(x2, y)
return fit.predict(x2) |
@statmike The linked PR will fix the issue. I tested that your code would work after a minor fix. In your class_metrics.log_confusion_matrix(['Not Fraud', 'Fraud'], cm) should be updated to class_metrics.log_confusion_matrix(['Not Fraud', 'Fraud'], cm.tolist()) because |
Thank you @chensun for the very fast response and fix. I look forward to using this once it is merged! |
Hello @chensun Running
|
@statmike, thank you for raising this. This is indeed a bug. After some investigation, it happens (at least) in the case when the longest path of the import graph ending at the component involves >2 modules. For example: # component.py
from module_one import one
@dsl.component
def comp(): ... # module_one.py
from module_two import two
one = 1 # module_two.py
two = 2 The fix isn't immediately clear, but I will add this as a bug and look into it. |
@connor-mccarthy thank you for the quick validation. Do I need to open another issue for tracking? I notice this one is closed. |
…#8353 (kubeflow#8359) * Update component.py * Update component.py * Update component.py
kfp.__version__ = 1.8.14
Trying the instructions at 2. Containerized Python components:
kfp component build ...
results in error: "Error: No such command 'component'."kfp component
tokfp components
seem to get pass the command issuekfp components build
throw errors for*.py
files that do not contain components:ERROR: No KFP components found in file ...
*.py
file are modules imported by the file.py with component definitions using relative imports. This seems to beexactly how the example is laid out doc example
The text was updated successfully, but these errors were encountered: