@@ -242,72 +242,72 @@ static void getMemoryAndProcessors(
242242 final int numMissingProcessors = numMissingAllocations * numberOfThreadsPerAllocation ;
243243 int numExistingProcessorsToBeUsed = Math .min (numMissingProcessors , numberOfAvailableProcessors );
244244
245+ if (numberOfRequestedAllocations == 0 ) {
246+ continue ;
247+ }
245248 if (assignment .getNodeRoutingTable ().isEmpty () == false
246249 && assignment .getNodeRoutingTable ().values ().stream ().allMatch (r -> r .getState ().consumesMemory () == false )) {
247250 // Ignore states that don't consume memory, for example all allocations are failed or stopped
248251 // if the node routing table is empty, then it will match the above condition, but it needs to be handled in the next branch
249252 continue ;
253+ }
254+
255+ if (assignment .getNodeRoutingTable ().isEmpty () == false ) {
256+ // if the routing table is non-empty, this is an existing model
257+ existingModelMemoryBytes += estimatedMemoryUsage ;
250258 } else {
259+ // only increase memory requirements for new models
260+ extraPerNodeModelMemoryBytes += Math .max (extraPerNodeModelMemoryBytes , estimatedMemoryUsage );
261+ extraModelMemoryInBytes += estimatedMemoryUsage ;
262+ }
251263
252- if ( assignment . getNodeRoutingTable (). isEmpty () == false ) {
253- // if the routing table is non-empty, this is an existing model
254- existingModelMemoryBytes += estimatedMemoryUsage ;
255- } else {
256- // only increase memory requirements for new models
257- extraPerNodeModelMemoryBytes + = Math .max (extraPerNodeModelMemoryBytes , estimatedMemoryUsage );
258- extraModelMemoryInBytes += estimatedMemoryUsage ;
264+ // if not low priority, check processor requirements.
265+ if ( Priority . LOW . equals ( modelAssignment . getValue (). getTaskParams (). getPriority ()) == false ) {
266+ if ( numMissingProcessors > numberOfAvailableProcessors ) {
267+ // as assignments can be placed on different nodes, we only need numberOfThreadsPerAllocation here
268+ extraProcessors += numMissingProcessors - numExistingProcessorsToBeUsed ;
269+ extraPerNodeProcessors = Math .max (extraPerNodeProcessors , 1 ); // if extra processors >0, we need at least 1
270+ // extraPerNodeProcessors
259271 }
260-
261- // if not low priority, check processor requirements.
262- if (Priority .LOW .equals (modelAssignment .getValue ().getTaskParams ().getPriority ()) == false ) {
263- if (numMissingProcessors > numberOfAvailableProcessors ) {
264- // as assignments can be placed on different nodes, we only need numberOfThreadsPerAllocation here
265- extraProcessors += numMissingProcessors - numExistingProcessorsToBeUsed ;
266- extraPerNodeProcessors = Math .max (extraPerNodeProcessors , 1 ); // if extra processors >0, we need at least 1
267- // extraPerNodeProcessors
268- }
269- if (perNodeAvailableProcessors < numberOfThreadsPerAllocation ) {
270- extraPerNodeProcessors = Math .max (extraPerNodeProcessors , numberOfThreadsPerAllocation );
271- }
272- numberOfAvailableProcessors -= numExistingProcessorsToBeUsed ;
272+ if (perNodeAvailableProcessors < numberOfThreadsPerAllocation ) {
273+ extraPerNodeProcessors = Math .max (extraPerNodeProcessors , numberOfThreadsPerAllocation );
273274 }
275+ numberOfAvailableProcessors -= numExistingProcessorsToBeUsed ;
276+ }
277+
278+ if (extraProcessors > 0 || extraPerNodeProcessors > 0 || extraModelMemoryInBytes > 0 || extraPerNodeModelMemoryBytes > 0 ) {
279+ logger .info (
280+ () -> format (
281+ "trained model [%s] assigned to [%s], waiting for [%d] allocations to start due to missing hardware" ,
282+ modelAssignment .getKey (),
283+ Strings .arrayToCommaDelimitedString (modelAssignment .getValue ().getStartedNodes ()),
284+ numMissingAllocations
285+ )
286+ );
287+ }
274288
275- if (extraProcessors > 0 || extraPerNodeProcessors > 0 || extraModelMemoryInBytes > 0 || extraPerNodeModelMemoryBytes > 0 ) {
276- logger .info (
277- () -> format (
278- "trained model [%s] assigned to [%s], waiting for [%d] allocations to start due to missing hardware" ,
279- modelAssignment .getKey (),
280- Strings .arrayToCommaDelimitedString (modelAssignment .getValue ().getStartedNodes ()),
281- numMissingAllocations
289+ for (String node : modelAssignment .getValue ().getNodeRoutingTable ().keySet ()) {
290+ sumOfCurrentlyExistingAndUsedProcessors += modelAssignment .getValue ().getNodeRoutingTable ().get (node ).getTargetAllocations ()
291+ * numberOfThreadsPerAllocation ;
292+
293+ jobRequirementsByNode .computeIfAbsent (node , k -> new ArrayList <>())
294+ .add (
295+ MlJobRequirements .of (
296+ estimatedMemoryUsage ,
297+ Priority .LOW .equals (modelAssignment .getValue ().getTaskParams ().getPriority ())
298+ ? 0
299+ : modelAssignment .getValue ().getNodeRoutingTable ().get (node ).getTargetAllocations ()
300+ * numberOfThreadsPerAllocation
282301 )
283302 );
284- }
285-
286- for (String node : modelAssignment .getValue ().getNodeRoutingTable ().keySet ()) {
287- sumOfCurrentlyExistingAndUsedProcessors += modelAssignment .getValue ()
288- .getNodeRoutingTable ()
289- .get (node )
290- .getTargetAllocations () * numberOfThreadsPerAllocation ;
291-
292- jobRequirementsByNode .computeIfAbsent (node , k -> new ArrayList <>())
293- .add (
294- MlJobRequirements .of (
295- estimatedMemoryUsage ,
296- Priority .LOW .equals (modelAssignment .getValue ().getTaskParams ().getPriority ())
297- ? 0
298- : modelAssignment .getValue ().getNodeRoutingTable ().get (node ).getTargetAllocations ()
299- * numberOfThreadsPerAllocation
300- )
301- );
302- }
303-
304- // min(3, max(number of allocations over all deployed models)
305- // the minimum number of nodes is equal to the number of allocations, up to 3
306- // if the number of allocations is greater than 3, then wantedMinNodes is still 3
307- // in theory this should help availability for 2-3 allocations
308- // the planner should split over all available nodes
309- minNodes = Math .min (3 , Math .max (minNodes , numberOfRequestedAllocations ));
310303 }
304+
305+ // min(3, max(number of allocations over all deployed models)
306+ // the minimum number of nodes is equal to the number of allocations, up to 3
307+ // if the number of allocations is greater than 3, then wantedMinNodes is still 3
308+ // in theory this should help availability for 2-3 allocations
309+ // the planner should split over all available nodes
310+ minNodes = Math .min (3 , Math .max (minNodes , numberOfRequestedAllocations ));
311311 }
312312
313313 // dummy autoscaling entity
0 commit comments