Bird
Raised Fist0
Prompt Engineering / GenAIml~20 mins

Cost optimization in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Cost Optimization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Cost Components in Machine Learning

Which of the following is NOT typically considered a direct cost component when optimizing machine learning model deployment?

ADeveloper salaries for model development
BCompute resources used during model training
CElectricity costs for powering data center cooling
DData storage costs for training datasets
Attempts:
2 left
💡 Hint

Think about costs directly tied to running and maintaining the model versus indirect overhead.

Model Choice
intermediate
2:00remaining
Choosing a Model for Cost Efficiency

You need to deploy a model on edge devices with limited compute and power. Which model type is the most cost-efficient choice?

ASmall convolutional neural network with quantization applied
BUncompressed recurrent neural network with high precision weights
CEnsemble of multiple deep neural networks
DLarge transformer-based model with billions of parameters
Attempts:
2 left
💡 Hint

Consider model size and computational requirements for edge deployment.

Metrics
advanced
2:00remaining
Evaluating Cost-Performance Tradeoff

Given two models with the following metrics:

  • Model A: Accuracy 92%, Inference cost $0.10 per 1000 predictions
  • Model B: Accuracy 90%, Inference cost $0.02 per 1000 predictions

Which metric best helps decide the cost-effectiveness of these models?

AInference cost alone
BAccuracy divided by inference cost
CAccuracy alone
DTraining time
Attempts:
2 left
💡 Hint

Think about combining accuracy and cost into one measure.

🔧 Debug
advanced
2:00remaining
Identifying Cost Bottleneck in Model Training Code

Consider this Python snippet for training a model:

for epoch in range(10):
    for batch in data_loader:
        outputs = model(batch)
        loss = loss_fn(outputs, batch.labels)
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        time.sleep(5)

What is the main cause of unnecessary cost increase?

ANot using GPU acceleration
BMissing learning rate scheduler
CThe time.sleep(5) call inside the training loop
DNot shuffling data_loader
Attempts:
2 left
💡 Hint

Look for code that delays training without benefit.

Hyperparameter
expert
3:00remaining
Optimizing Hyperparameters for Cost Reduction

You want to reduce training cost by adjusting batch size and learning rate. Which combination is most likely to reduce cost without hurting model convergence?

ADecrease batch size and decrease learning rate
BDecrease batch size and increase learning rate
CIncrease batch size and decrease learning rate
DIncrease batch size and increase learning rate
Attempts:
2 left
💡 Hint

Think about how batch size affects training speed and learning rate affects convergence.

Practice

(1/5)
1.

What is the main goal of cost optimization in machine learning?

easy
A. To reduce expenses while keeping good model accuracy
B. To make the model as large as possible
C. To use all available data regardless of cost
D. To increase training time for better results

Solution

  1. Step 1: Understand cost optimization meaning

    Cost optimization means saving money and resources in AI work.
  2. Step 2: Connect cost saving with accuracy

    Good cost optimization keeps accuracy high while lowering expenses.
  3. Final Answer:

    To reduce expenses while keeping good model accuracy -> Option A
  4. Quick Check:

    Cost optimization = reduce cost + keep accuracy [OK]
Hint: Cost optimization balances cost and accuracy [OK]
Common Mistakes:
  • Thinking bigger models always mean better cost
  • Ignoring accuracy when saving cost
  • Assuming more data always reduces cost
2.

Which of the following is the correct way to reduce training cost in AI?

options = [
  'Use smaller models',
  'Train on all data without filtering',
  'Increase batch size unnecessarily',
  'Use slower hardware'
]
easy
A. Use slower hardware
B. Train on all data without filtering
C. Use smaller models
D. Increase batch size unnecessarily

Solution

  1. Step 1: Identify cost-saving methods

    Using smaller models reduces computation and memory, lowering cost.
  2. Step 2: Evaluate other options

    Training on all data, increasing batch size unnecessarily, or using slower hardware increase cost or slow training.
  3. Final Answer:

    Use smaller models -> Option C
  4. Quick Check:

    Smaller models reduce cost [OK]
Hint: Smaller models usually cost less to train [OK]
Common Mistakes:
  • Thinking more data always reduces cost
  • Believing bigger batch size always helps
  • Assuming slower hardware saves money
3.

Consider this Python code that trains a model with different batch sizes to optimize cost:

batch_sizes = [16, 32, 64]
costs = []
for b in batch_sizes:
    cost = 1000 / b  # cost inversely proportional to batch size
    costs.append(cost)
print(costs)

What is the output of this code?

medium
A. [64, 32, 16]
B. [16, 32, 64]
C. [15.625, 31.25, 62.5]
D. [62.5, 31.25, 15.625]

Solution

  1. Step 1: Calculate cost for each batch size

    For batch size 16: 1000/16 = 62.5; for 32: 1000/32 = 31.25; for 64: 1000/64 = 15.625.
  2. Step 2: Collect costs in list and print

    The costs list becomes [62.5, 31.25, 15.625], which is printed.
  3. Final Answer:

    [62.5, 31.25, 15.625] -> Option D
  4. Quick Check:

    Cost = 1000 / batch size [OK]
Hint: Divide 1000 by each batch size to get costs [OK]
Common Mistakes:
  • Confusing batch sizes with costs
  • Mixing up division order
  • Copying batch_sizes list instead of costs
4.

Find the error in this code snippet that tries to reduce training cost by skipping data points:

data = [1, 2, 3, 4, 5]
reduced_data = [x for x in data if x > 3]
print(reduced_data)

What is the problem if the goal is to keep most data but reduce cost?

medium
A. It removes too many data points, hurting accuracy
B. It does not remove any data points
C. It causes a syntax error
D. It duplicates data points

Solution

  1. Step 1: Understand filtering condition

    The code keeps only data points greater than 3, removing 1, 2, 3.
  2. Step 2: Assess impact on data and cost

    Removing many points reduces data but may hurt model accuracy since much data is lost.
  3. Final Answer:

    It removes too many data points, hurting accuracy -> Option A
  4. Quick Check:

    Filtering >3 removes many points [OK]
Hint: Check how much data filtering removes [OK]
Common Mistakes:
  • Thinking it keeps most data
  • Expecting syntax error
  • Assuming data duplicates
5.

You want to optimize cost for training a language model. You have these options:

  • Use a smaller model
  • Train on a filtered smaller dataset
  • Use mixed precision training
  • Train longer with bigger batch size

Which combination best balances cost and accuracy?

hard
A. Train longer with bigger batch size only
B. Use smaller model + filtered dataset + mixed precision
C. Use smaller model only
D. Train on full dataset with no precision changes

Solution

  1. Step 1: Analyze each option's effect on cost and accuracy

    Smaller model reduces cost; filtered dataset reduces data size; mixed precision speeds training and saves memory.
  2. Step 2: Combine options for best balance

    Using all three together lowers cost while keeping good accuracy. Training longer with bigger batch size alone increases cost.
  3. Final Answer:

    Use smaller model + filtered dataset + mixed precision -> Option B
  4. Quick Check:

    Combine cost-saving methods for best results [OK]
Hint: Combine multiple cost-saving methods for best effect [OK]
Common Mistakes:
  • Choosing only one method
  • Ignoring accuracy impact
  • Assuming longer training always helps