snowflakedb / snowflake-ml-python

Apache License 2.0
37 stars 7 forks source link

SNOW-1096894: Calling multiple registered models in snowsql returns NULL output for all but the first model #89

Closed adaykoth closed 3 months ago

adaykoth commented 4 months ago

Suppose I have registered models m1, m2 and m3 in the core db under the schema models. The following query will return NULL for the second and third predict call:

SELECT
    id,
    core.models.m1!predict(a,b,c,),
    core.models.m2!predict(a,b,c,),
    core.models.m3!predict(a,b,c)
FROM features

Note that calling the models independently in a query produces correct results and switching the order of the model call also changes which model produces a non-null output. It is always the first one.

adaykoth commented 4 months ago

To update this: I've done a bit more testing and it appears that this does not generically return NULL. Instead what seems to happen is that the first model is called three times per row instead of three different models one time. This means that if you try to extract differently named outputs of the returned json, the return of the second and third model call will return null.

So as a minimal example:

SELECT core.test.model1!predict(0.1,0.1,0.1),
        core.test.model2!predict(0.1,0.1,0.1);

will return identical values, even if calling the model 2 separately will return a different value to model 1.

So in essence you can call at most one modell per query currently.

sfc-gh-sdas commented 4 months ago

Sorry for late reply. Given it is consistently reproducing for you with same signature functions, would you please confirm if you observe the same between two versions of same model? That is, store model2 as new version V2 inside model1 while keeping original as default version in model1 and call like:

WITH model2 AS model1 VERSION V2
    SELECT mv!predict(0.1,0.1,0.1), model1!predict(0.1,0.1,0.1);
sfc-gh-aponnusamy commented 4 months ago

Just to update @adaykoth - We are still investigating this issue. I tried this and the resolution seems to be ok. We will keep you posted if we discover something

snowman#REGRESS@MYDB.MYSCHEMA>select current_date(),mydb.myschema.mod1!snore(1),mydb.myschema.mod2!snore(1),mydb.myschema.mod3!snore(1) from (select 1);
+----------------+-----------------------------+-----------------------------+-----------------------------+
| CURRENT_DATE() | MYDB.MYSCHEMA.MOD1!SNORE(1) | MYDB.MYSCHEMA.MOD2!SNORE(1) | MYDB.MYSCHEMA.MOD3!SNORE(1) |
|----------------+-----------------------------+-----------------------------+-----------------------------|
| 2024-03-05     | [                           | [                           | [                           |
|                |   "my model1 - Zzz"         |   "my model2 - Zzz"         |   "my model3 - Zzz"         |
|                | ]                           | ]                           | ]                           |
+----------------+-----------------------------+-----------------------------+-----------------------------+

As you can see in the above example, I have three different models and each model is invoking its method.

sfc-gh-shchen commented 3 months ago

Hi @adaykoth fyi the team is actively working on the fix.

sfc-gh-wzhao commented 3 months ago

Hi @adaykoth ,

We have identified the root cause and implemented the fix in the just released 1.4.0 version. You need to upgrade and re-log your model so that they could work in the same query. We are closing this issue, however, if you have any problems or find this issue still exists, please reopen it. Thank you for your support!