-
Notifications
You must be signed in to change notification settings - Fork 2
Check input dimensions #76
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -856,3 +856,29 @@ def test_wide_data(): | |||||||||||||||||||
| # Inference should run without crashing | ||||||||||||||||||||
| fm = nvforest.load_from_sklearn(clf) | ||||||||||||||||||||
| _ = fm.predict(X) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @pytest.mark.parametrize("input_size", [4, 6], ids=["too_narrow", "too_wide"]) | ||||||||||||||||||||
| @pytest.mark.parametrize( | ||||||||||||||||||||
| "predict_func", | ||||||||||||||||||||
| [ | ||||||||||||||||||||
| nvforest.CPUForestInferenceClassifier.predict, | ||||||||||||||||||||
| nvforest.CPUForestInferenceClassifier.predict_per_tree, | ||||||||||||||||||||
| nvforest.CPUForestInferenceClassifier.apply, | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| ids=["predict", "predict_per_tree", "apply"], | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| def test_incorrect_data_shape(input_size, predict_func): | ||||||||||||||||||||
| n_rows = 50 | ||||||||||||||||||||
| n_features = 5 | ||||||||||||||||||||
| X = np.random.normal(size=(n_rows, n_features)).astype(np.float32) | ||||||||||||||||||||
| y = np.asarray([0, 1] * (n_rows // 2), dtype=np.int32) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| clf = RandomForestClassifier(max_features="sqrt", n_estimators=10) | ||||||||||||||||||||
| clf.fit(X, y) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| fm = nvforest.load_from_sklearn(clf, device="cpu") | ||||||||||||||||||||
| assert fm.num_features == n_features | ||||||||||||||||||||
| with pytest.raises(ValueError, match=f"Expected {n_features} features"): | ||||||||||||||||||||
| X_test = np.zeros((1, input_size)) | ||||||||||||||||||||
| _ = predict_func(fm, X_test) | ||||||||||||||||||||
|
Comment on lines
+882
to
+884
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert the received feature count in the error message too. Right now any message that starts with Suggested assertion tightening- with pytest.raises(ValueError, match=f"Expected {n_features} features"):
+ with pytest.raises(
+ ValueError,
+ match=rf"Expected {n_features} features.*got {input_size}",
+ ):As per coding guidelines "Error messages should be helpful and include expected vs actual values". 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cover the actual issue-72 loading path here.
This only exercises
load_from_sklearn(..., device="cpu"), but issue#72is about feature-count validation after loading a serialized model viaForestInference.load/nvforest.load_model. A loader-specificnum_featuresregression would still slip through, so please add at least one saved-model case that goes throughload_modeland reproduces the user-facing path.🤖 Prompt for AI Agents