-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat: support newer azure deployments #478
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -612,16 +612,8 @@ def __init__( | |
max_wait_time=max_wait_time, | ||
) | ||
self._model_params: Dict[Tuple[str, str], Tuple[int, int]] = {} | ||
if "ai.azure" in base_url: | ||
from packaging.version import Version | ||
|
||
import nixtla | ||
|
||
if Version(nixtla.__version__) > Version("0.5.2"): | ||
raise NotImplementedError( | ||
"This version doesn't support Azure endpoints, please install " | ||
"an earlier version with: `pip install 'nixtla<=0.5.2'`" | ||
) | ||
self._is_azure = "ai.azure" in base_url | ||
if self._is_azure: | ||
self.supported_models = ["azureai"] | ||
else: | ||
self.supported_models = ["timegpt-1", "timegpt-1-long-horizon"] | ||
|
@@ -643,7 +635,6 @@ def ensure_contiguous_arrays(d: Dict[str, Any]) -> None: | |
) | ||
else: | ||
d[k] = np.ascontiguousarray(v) | ||
|
||
elif isinstance(v, dict): | ||
ensure_contiguous_arrays(v) | ||
|
||
|
@@ -737,6 +728,11 @@ def _make_partitioned_requests( | |
).T | ||
return resp | ||
|
||
def _maybe_override_model(self, model: str) -> str: | ||
if self._is_azure: | ||
model = "azureai" | ||
return model | ||
|
||
def _get_model_params(self, model: str, freq: str) -> Tuple[int, int]: | ||
key = (model, freq) | ||
if key not in self._model_params: | ||
|
@@ -766,11 +762,23 @@ def _maybe_assign_weights( | |
|
||
def _maybe_assign_feature_contributions( | ||
self, | ||
feature_contributions: Optional[List[List[float]]], | ||
expected_contributions: bool, | ||
resp: Dict[str, Any], | ||
x_cols: List[str], | ||
out_df: DataFrame, | ||
insample_feat_contributions: Optional[List[List[float]]], | ||
) -> None: | ||
if not expected_contributions: | ||
return | ||
if "feature_contributions" not in resp: | ||
if self._is_azure: | ||
warnings.warn("feature_contributions aren't implemented in Azure yet.") | ||
return | ||
else: | ||
raise RuntimeError( | ||
"feature_contributions expected in response but not found" | ||
) | ||
feature_contributions = resp["feature_contributions"] | ||
if feature_contributions is None: | ||
return | ||
shap_cols = x_cols + ["base_value"] | ||
|
@@ -959,6 +967,7 @@ def forecast( | |
) | ||
self.__dict__.pop("weights_x", None) | ||
self.__dict__.pop("feature_contributions", None) | ||
model = self._maybe_override_model(model) | ||
logger.info("Validating inputs...") | ||
df, X_df, drop_id = self._run_validations( | ||
df=df, | ||
|
@@ -1046,13 +1055,11 @@ def forecast( | |
in_sample_payload = _forecast_payload_to_in_sample(payload) | ||
logger.info("Calling Historical Forecast Endpoint...") | ||
in_sample_resp = self._make_request_with_retries( | ||
client, | ||
"v2/historic_forecast", | ||
in_sample_payload, | ||
client, "v2/historic_forecast", in_sample_payload | ||
) | ||
insample_feat_contributions = in_sample_resp.get( | ||
"feature_contributions", None | ||
) | ||
insample_feat_contributions = in_sample_resp[ | ||
"feature_contributions" | ||
] | ||
else: | ||
payloads = _partition_series(payload, num_partitions, h) | ||
resp = self._make_partitioned_requests(client, "v2/forecast", payloads) | ||
|
@@ -1062,13 +1069,11 @@ def forecast( | |
] | ||
logger.info("Calling Historical Forecast Endpoint...") | ||
in_sample_resp = self._make_partitioned_requests( | ||
client, | ||
"v2/historic_forecast", | ||
in_sample_payloads, | ||
client, "v2/historic_forecast", in_sample_payloads | ||
) | ||
insample_feat_contributions = in_sample_resp.get( | ||
"feature_contributions", None | ||
) | ||
insample_feat_contributions = in_sample_resp[ | ||
"feature_contributions" | ||
] | ||
|
||
# assemble result | ||
out = ufp.make_future_dataframe( | ||
|
@@ -1094,7 +1099,8 @@ def forecast( | |
in_sample_df = ufp.drop_columns(in_sample_df, target_col) | ||
out = ufp.vertical_concat([in_sample_df, out]) | ||
self._maybe_assign_feature_contributions( | ||
feature_contributions=resp["feature_contributions"], | ||
expected_contributions=feature_contributions, | ||
resp=resp, | ||
x_cols=x_cols, | ||
out_df=out[[id_col, time_col, "TimeGPT"]], | ||
insample_feat_contributions=insample_feat_contributions, | ||
|
@@ -1109,7 +1115,6 @@ def forecast( | |
self.feature_contributions = ufp.take_rows( | ||
self.feature_contributions, sort_idxs | ||
) | ||
|
||
out = _maybe_drop_id(df=out, id_col=id_col, drop=drop_id) | ||
self._maybe_assign_weights(weights=resp["weights_x"], df=df, x_cols=x_cols) | ||
return out | ||
|
@@ -1201,6 +1206,8 @@ def detect_anomalies( | |
num_partitions=num_partitions, | ||
) | ||
self.__dict__.pop("weights_x", None) | ||
model = self._maybe_override_model(model) | ||
logger.info("Validating inputs...") | ||
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. cool |
||
df, _, drop_id = self._run_validations( | ||
df=df, | ||
X_df=None, | ||
|
@@ -1385,6 +1392,8 @@ def cross_validation( | |
model=model, | ||
num_partitions=num_partitions, | ||
) | ||
model = self._maybe_override_model(model) | ||
logger.info("Validating inputs...") | ||
df, _, drop_id = self._run_validations( | ||
df=df, | ||
X_df=None, | ||
|
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 |
---|---|---|
|
@@ -44,7 +44,6 @@ | |
"fastcore", | ||
"httpx", | ||
"orjson", | ||
"packaging", | ||
"pandas", | ||
"pydantic", | ||
"tenacity", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice