yesterday
Hi,
I see that ai-query supports parallelization. Is it executed in parallel across each partition of the dataframe.
could any one explain how it supports optimized batch inference
yesterday
Hi @IM_01, ai_query is built for batch inference, but the docs do not say that it runs one call per DataFrame partition, and they do not describe the internal batching. They say the platform manages it. The AI Functions page says: "AI Functions automatically manage parallelization, retries, and scaling. It is advised to submit your full dataset in a single query rather than manually splitting it into small batches." The same page says "your query runs on the compute you submit it from, such as a SQL warehouse, notebook, cluster, or pipeline", and that "the model inference may run on separate Databricks-managed infrastructure". So the docs do not link the number of partitions to the number of parallel model calls, and I would not tune partitions for this. For optimised batch inference, the best practices on the "Use ai_query" page are: 1) Use Databricks-hosted system.ai model services, not provisioned throughput endpoints. 2) Pick a model from the batch-optimised list on that page. A non-optimised model "can result in reduced throughput and longer job completion times." 3) Submit your full dataset in a single query. "Manually splitting data into small batches can reduce throughput." 4) Set failOnError to false for large workloads, so failed rows return an error message and you keep the successful results.
[https://docs.databricks.com/aws/en/large-language-models/ai-query]
To see what happened in a run, open the query profile in the SQL editor and click AI Query. It shows the completed and failed inferences and the total time.
yesterday
Hi @IM_01, ai_query is built for batch inference, but the docs do not say that it runs one call per DataFrame partition, and they do not describe the internal batching. They say the platform manages it. The AI Functions page says: "AI Functions automatically manage parallelization, retries, and scaling. It is advised to submit your full dataset in a single query rather than manually splitting it into small batches." The same page says "your query runs on the compute you submit it from, such as a SQL warehouse, notebook, cluster, or pipeline", and that "the model inference may run on separate Databricks-managed infrastructure". So the docs do not link the number of partitions to the number of parallel model calls, and I would not tune partitions for this. For optimised batch inference, the best practices on the "Use ai_query" page are: 1) Use Databricks-hosted system.ai model services, not provisioned throughput endpoints. 2) Pick a model from the batch-optimised list on that page. A non-optimised model "can result in reduced throughput and longer job completion times." 3) Submit your full dataset in a single query. "Manually splitting data into small batches can reduce throughput." 4) Set failOnError to false for large workloads, so failed rows return an error message and you keep the successful results.
[https://docs.databricks.com/aws/en/large-language-models/ai-query]
To see what happened in a run, open the query profile in the SQL editor and click AI Query. It shows the completed and failed inferences and the total time.
10 hours ago - last edited 10 hours ago
Hi @IM_01 ,
Short answer: yes, ai_query works in parallel, but partitions aren't really the lever. Parallelism happens at two levels, and Databricks manages the important one for you.
1. Spark side (your DataFrame)
ai_query is evaluated like any other Spark SQL expression, so rows are processed by Spark tasks, and partitions are processed in parallel across the cluster's cores. In most cases Spark sizes the partitions adaptively, so you don't need to tune anything.
2. Model-serving side (where the optimised batch inference happens)
This is usually the real bottleneck, and AI Functions "automatically handle paralleliation, retries, and scaling" for it. With a batch-optimised Databricks-hosted model, the batch backend scales capacity up for your query automatically. You don't provision or configure endpoint compute.
Should I repartition?
Usually no. The docs advise submitting your full dataset in a single query and warn that "manually splitting data into small batches can reduce throughput." The exception is input that is clearly under-partitioned, such as a small CSV read into one or two partitions on classic compute with idle cores. There, a modest repartition(n) with n roughly equal to the available cores can help. Benchmark it: too many partitions gives diminishing returns, and repartitioning doesn't change cost.
How to get the optimised batch path:First, make sure:
Then follow the steps that were mentioned in the previous comments:
CREATE OR REPLACE TABLE results AS
SELECT id, ai_query('databricks-โฆ', prompt, failOnError => false) AS ai
FROM source;โUse one ai_query session per model rather than several running side by side. Persist the results to a table instead of re-running inference in later queries.Docs:
Good luck
10 hours ago
could u please elaborate on second level i.e; model serving side