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
Hardware and Framework Version Tracking
📖 Scenario: You work in a machine learning team. You want to keep track of the hardware and software versions used for training models. This helps your team reproduce results and debug issues.
🎯 Goal: Create a Python dictionary to store hardware and framework versions. Add a configuration variable for the minimum required framework version. Then filter the dictionary to keep only versions that meet or exceed this minimum. Finally, print the filtered versions.
📋 What You'll Learn
Create a dictionary called versions with exact keys and values
Add a variable called min_framework_version with the exact value 2.0
Use a dictionary comprehension to create valid_versions with framework versions >= min_framework_version
Print the valid_versions dictionary
💡 Why This Matters
🌍 Real World
Tracking hardware and software versions helps teams reproduce machine learning experiments and debug issues effectively.
💼 Career
Version tracking is a key skill for MLOps engineers to ensure consistent environments and smooth collaboration.
Progress0 / 4 steps
1
Create the versions dictionary
Create a dictionary called versions with these exact entries: 'GPU': 'NVIDIA RTX 3090', 'CPU': 'Intel i9-11900K', 'Framework': '2.3', 'CUDA': '11.2'
MLOps
Hint
Use curly braces {} to create a dictionary. Separate keys and values with colons. Use quotes for strings.
2
Add minimum framework version
Add a variable called min_framework_version and set it to the string '2.0'
MLOps
Hint
Assign the string '2.0' to the variable min_framework_version.
3
Filter versions by minimum framework version
Use a dictionary comprehension to create a new dictionary called valid_versions that includes all items from versions where the key is not 'Framework' or the value of 'Framework' is greater than or equal to min_framework_version. Convert the version strings to floats for comparison.
MLOps
Hint
Use {k: v for k, v in versions.items() if ...} and convert version strings to floats for comparison.
4
Print the filtered versions
Print the valid_versions dictionary using print(valid_versions)
MLOps
Hint
Use the print function to display the dictionary.
Practice
(1/5)
1. Why is it important to track hardware and framework versions in MLOps?
easy
A. To reduce the size of the model files
B. To make the code run faster on any machine
C. To ensure experiments can be reproduced exactly later
D. To avoid using any cloud services
Solution
Step 1: Understand reproducibility in experiments
Reproducibility means you can get the same results again by using the same setup.
Step 2: Connect version tracking to reproducibility
Tracking hardware and framework versions helps recreate the exact environment for experiments.
Final Answer:
To ensure experiments can be reproduced exactly later -> Option C
Quick Check:
Reproducibility = Track versions [OK]
Hint: Reproducibility needs exact version info [OK]
Common Mistakes:
Thinking tracking speeds up code
Confusing version tracking with file size
Assuming cloud use is related
2. Which of the following is the correct way to store framework version in a Python dictionary for tracking?
easy
A. versions = {"tensorflow": "2.12.0"}
B. versions = (tensorflow: 2.12.0)
C. versions = [tensorflow = "2.12.0"]
D. versions = {tensorflow => "2.12.0"}
Solution
Step 1: Recall Python dictionary syntax
Python dictionaries use curly braces with key: value pairs, keys and values as strings need quotes.
Step 2: Check each option's syntax
versions = {"tensorflow": "2.12.0"} uses correct syntax with quotes and colon. Others use invalid syntax for Python dictionaries.
B. NameError because NVIDIA RTX 4090 is not quoted
C. SyntaxError due to invalid dictionary
D. KeyError because GPU key is missing
Solution
Step 1: Check the assignment line syntax
The value NVIDIA RTX 4090 is not in quotes, so Python treats it as variable names.
Step 2: Understand Python error for undefined names
Since no variable named NVIDIA exists, Python raises a NameError.
Final Answer:
NameError because NVIDIA RTX 4090 is not quoted -> Option B
Quick Check:
Unquoted strings cause NameError [OK]
Hint: Always quote string values in Python [OK]
Common Mistakes:
Thinking KeyError occurs for existing keys
Assuming syntax error instead of NameError
Believing code runs without error
5. You want to track both hardware and framework versions in one dictionary. Which code correctly updates the framework version without losing hardware info?
versions = {"hardware": {"GPU": "NVIDIA RTX 3090"}, "framework": {"tensorflow": "2.11.0", "torch": "1.13.0"}}
# Update tensorflow to 2.12.0 here
hard
A. versions.update({"tensorflow": "2.12.0"})
B. versions["framework"] = {"tensorflow": "2.12.0"}
C. versions["tensorflow"] = "2.12.0"
D. versions["framework"]["tensorflow"] = "2.12.0"
Solution
Step 1: Understand nested dictionary structure
"framework" key holds a dictionary with tensorflow version inside.
Step 2: Update tensorflow version inside nested dictionary
Use versions["framework"]["tensorflow"] = "2.12.0" to update without overwriting hardware info.
Step 3: Check other options for overwriting risk
versions["framework"] = {"tensorflow": "2.12.0"} replaces entire framework dict, versions["tensorflow"] = "2.12.0" and D add keys at top level, losing structure.
Final Answer:
versions["framework"]["tensorflow"] = "2.12.0" -> Option D
Quick Check:
Update nested dict key correctly [OK]
Hint: Update nested dict keys to keep all info [OK]