Skip to content
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

Pass hyper params from client #21

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "tabpfn-client"
version = "0.0.11"
version = "0.0.12"
requires-python = ">=3.10"
dependencies = [
"httpx>=0.24.1",
Expand Down
2 changes: 1 addition & 1 deletion quick_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

else:
tabpfn_classifier.init()
tabpfn = TabPFNClassifier(model="latest_tabpfn_hosted")
tabpfn = TabPFNClassifier(model="latest_tabpfn_hosted", n_estimators=3)
# print("checking estimator", check_estimator(tabpfn))
tabpfn.fit(X_train[:99], y_train[:99])
print("predicting")
Expand Down
2 changes: 1 addition & 1 deletion tabpfn_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def predict(self, train_set_uid: str, x_test, tabpfn_config: dict | None=None):

self._validate_response(response, "predict")

return np.array(response.json()["y_pred"])
return np.array(response.json()["y_pred_proba"])

@staticmethod
def _validate_response(response, method_name, only_version_check=False):
Expand Down
2 changes: 1 addition & 1 deletion tabpfn_client/prompt_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def prompt_and_set_token(cls, user_auth_handler: "UserAuthenticationClient"):
# Registration
if choice == "1":
# validation_link = input(cls.indent("Please enter your secret code: "))
validation_link = "tabpfn-2023"
validation_link = "tabpfn-test"
SamuelGabriel marked this conversation as resolved.
Show resolved Hide resolved
while True:
email = input(cls.indent("Please enter your email: "))
# Send request to server to check if email is valid and not already taken.
Expand Down
13 changes: 7 additions & 6 deletions tabpfn_client/server_config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## testing
#protocol: "http"
#host: "0.0.0.0"
#port: "8000"
protocol: "http"
host: "localhost"
port: "8080"

# production
protocol: "https"
host: "tabpfn-server-wjedmz7r5a-ez.a.run.app"
port: "443"
#protocol: "https"
#host: "tabpfn-server-wjedmz7r5a-ez.a.run.app"
#host: tabpfn-server-preprod-wjedmz7r5a-ez.a.run.app # preprod
#port: "443"
endpoints:
root:
path: "/"
Expand Down
2 changes: 1 addition & 1 deletion tabpfn_client/tabpfn_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(
def fit(self, X, y):
# assert init() is called
if not g_tabpfn_config.is_initialized:
raise RuntimeError("TabPFNClassifier.init() must be called before using TabPFNClassifier")
raise RuntimeError("tabpfn_client.init() must be called before using TabPFNClassifier")

if g_tabpfn_config.use_server:
try:
Expand Down
2 changes: 1 addition & 1 deletion tabpfn_client/tabpfn_common_utils
2 changes: 1 addition & 1 deletion tabpfn_client/tests/integration/test_tabpfn_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_use_remote_tabpfn_classifier(self, mock_server):
# mock prediction
mock_server.router.post(mock_server.endpoints.predict.path).respond(
200,
json={"y_pred": LocalTabPFNClassifier().fit(self.X_train, self.y_train).predict_proba(self.X_test).tolist()}
json={"y_pred_proba": LocalTabPFNClassifier().fit(self.X_train, self.y_train).predict_proba(self.X_test).tolist()}
)
pred = tabpfn.predict(self.X_test)
self.assertEqual(pred.shape[0], self.X_test.shape[0])
4 changes: 2 additions & 2 deletions tabpfn_client/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def test_predict_with_valid_train_set_and_test_set(self, mock_server):

self.client.upload_train_set(self.X_train, self.y_train)

dummy_result = {"y_pred": [1, 2, 3]}
dummy_result = {"y_pred_proba": [1, 2, 3]}
mock_server.router.post(mock_server.endpoints.predict.path).respond(
200, json=dummy_result)

pred = self.client.predict(
train_set_uid=dummy_json["train_set_uid"],
x_test=self.X_test
)
self.assertTrue(np.array_equal(pred, dummy_result["y_pred"]))
self.assertTrue(np.array_equal(pred, dummy_result["y_pred_proba"]))

@with_mock_server()
def test_add_user_information(self, mock_server):
Expand Down
9 changes: 6 additions & 3 deletions tabpfn_client/tests/unit/test_tabpfn_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def test_init_remote_classifier(self, mock_server, mock_prompt_for_terms_and_con
mock_server.router.get(mock_server.endpoints.retrieve_greeting_messages.path).respond(
200, json={"messages": []})
mock_predict_response = [[1, 0.],[.9, .1],[0.01, 0.99]]
mock_server.router.post(mock_server.endpoints.predict.path).respond(
200, json={"y_pred": mock_predict_response}
predict_route = mock_server.router.post(mock_server.endpoints.predict.path)
predict_route.respond(
200, json={"y_pred_proba": mock_predict_response}
)

tabpfn_classifier.init(use_server=True)

tabpfn = TabPFNClassifier()
tabpfn = TabPFNClassifier(n_estimators=10)
self.assertRaises(
NotFittedError,
tabpfn.predict,
Expand All @@ -69,6 +70,8 @@ def test_init_remote_classifier(self, mock_server, mock_prompt_for_terms_and_con
y_pred = tabpfn.predict(self.X_test)
self.assertTrue(np.all(np.argmax(mock_predict_response, axis=1) == y_pred))

self.assertIn('n_estimators%22%3A%2010', str(predict_route.calls.last.request.url), "check that n_estimators is passed to the server")

@with_mock_server()
def test_reuse_saved_access_token(self, mock_server):
# mock connection and authentication
Expand Down
Loading