This repository demonstrates the Code Generation capabilities of AI models (specifically Qwen3-Coder) running on the Ampere Altra and AmpereOne platforms. It provides a suite of example prompts and utilities to generate, test, and validate Python code solutions for algorithmic problems.
Automatic Code Generation is a complex task that goes beyond simple text completion. Models must understand logic, handle edge cases, and adhere to strict syntax rules. Common challenges include:
- Algorithmic Logic: Converting a problem statement (e.g., "Find the missing number") into a working algorithm.
- Edge Case Handling: Ensuring code doesn't crash on empty inputs, negative numbers, or boundary conditions.
- Syntactic Correctness: Generating valid Python code that interprets and runs without errors.
- Testability: Creating self-contained solutions that include assertions to verify their own correctness.
This project leverages the efficient inference capabilities of Ampere Altra and AmpereOne processors to run high-performance code generation models using Ampere optimized llama.cpp.
- Efficient Inference: Run state-of-the-art coding models like Qwen3-Coder efficiently on Cloud Native Processors.
- Standardized Examples: Includes a curated list of 20 algorithms (Simple and Medium complexity) to explore model performance.
- Self-Verifying Code: The prompts are designed to request not just the solution, but also the test functions to verify correctness automatically.
- Ampere Optimized llama.cpp: A backend inference engine highly tuned for Ampere CPUs.
- Open-WebUI: An extensible, self-hosted UI for interacting with the LLMs.
- Qwen3-Coder: A state-of-the-art code generation model.
The solution uses Docker to orchestrate the interaction between the User (via Open-WebUI) and the AI Model (via Ampere Optimized llama.cpp).
graph LR
%% Styles for nodes
classDef nodeStyle fill:#fff,stroke:#000,stroke-width:1px,rx:5,ry:5;
%% Left Column: Input
subgraph UI [Open-WebUI]
direction TB
A[User Enters<br>Algorithm Prompt]
end
%% Middle Column: Inference
subgraph Inference [Ampere Inference]
direction TB
C[Ampere Optimized<br>llama.cpp Server]
end
%% Right Column: Output
subgraph Output [Code Execution]
direction TB
D[Generated Python<br>Code returned]
E[Test Function<br>Executed]
F[Result Verified]
end
%% Connections
A --> C
C --> D
D --> E
E --> F
%% Apply Styles
class A,B,C,D,E,F nodeStyle
%% Color the Subgraphs
style UI fill:#ffdce0,stroke:#333,stroke-width:2px
style Inference fill:#dcf5dc,stroke:#333,stroke-width:2px
style Output fill:#dcebf5,stroke:#333,stroke-width:2px
Ensure your environment meets the following requirements:
- Ampere Altra / AmpereOne System (Recommended)
- Docker Engine & Docker Compose
The application is configured directly via the compose.yaml file. You can modify the environment variables under the service definitions to change model parameters or file paths.
services:
llama-cpp-server:
image: amperecomputingai/llama.cpp:3.4.0
environment:
# Model Configuration
- LLAMA_ARG_HF_REPO=unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Qwen3-Coder-30B-A3B-Instruct-Q8_0.ggufUse the provided helper script to build and start the services.
./start-app.shTo stop the services and clean up resources:
./stop-app.shThis repository includes a suite of 20 prompts covering simple and medium-complexity algorithms, designed for testing code generation models (like Qwen3-Coder). Each prompt explicitly requests a Python solution and a corresponding test function.
-
FizzBuzz
Write a Python function named
fizz_buzz(n: int) -> List[str]that returns a list of strings representing the numbers from 1 ton. For multiples of 3, use 'Fizz'; for multiples of 5, use 'Buzz'; and for multiples of both, use 'FizzBuzz'. Include atest_fizz_buzz()function that uses assertions to verify the output forn=15. -
Palindrome Checker
Create a Python function
is_palindrome(s: str) -> boolthat checks if a given string is a palindrome, ignoring case, spaces, and non-alphanumeric characters. Add a test function containing assertions for cases like 'A man, a plan, a canal: Panama' (True) and 'hello' (False). -
Factorial Calculation
Write a recursive Python function
factorial(n: int) -> intto calculate the factorial of a non-negative integer. Include error handling for negative inputs. Provide a test function that asserts the results forn=0,n=1, andn=5, and checks that aValueErroris raised for negative input. -
Fibonacci Generator
Implement a Python generator function
fibonacci_generator(n: int)that yields the firstnnumbers of the Fibonacci sequence. Write a test function that consumes the generator and asserts that the output list forn=10matches[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]. -
Check Prime Number
Write a Python function
is_prime(num: int) -> boolto determine if a number is prime, optimized by checking divisibility up to the square root. Include atest_is_prime()function that assertsTruefor 2, 3, 17 andFalsefor 1, 4, 15. -
Find Missing Number
Given a list containing
ndistinct numbers taken from the range0ton, write a functionfind_missing_number(nums: List[int]) -> int. Include a test function that verifies inputs like[3, 0, 1]returns2and[0, 1]returns2. -
Remove Duplicates from Sorted Array
Write a Python function
remove_duplicates(nums: List[int]) -> intthat removes duplicates from a sorted array in-place and returns the new length. Include a test function that passes[1, 1, 2], asserts the return value is 2, and verifiesnumsis modified to[1, 2]. -
Valid Anagram
Write a Python function
is_anagram(s: str, t: str) -> boolto check iftis an anagram ofs. Provide a test function using assertions to check pairs like('anagram', 'nagaram')and('rat', 'car'). -
Matrix Transpose
Create a Python function
transpose_matrix(matrix: List[List[int]]) -> List[List[int]]that returns the transpose of a 2D matrix. Include a test function that verifies the transpose of[[1,2,3], [4,5,6]]is[[1,4], [2,5], [3,6]]. -
Sum of Digits (Digital Root)
Write a Python function
sum_of_digits(n: int) -> intthat repeatedly sums the digits of a number until the result has only one digit. Include a test function checkingn=38(result 2) andn=0(result 0).
-
Two Sum
Write a Python function
two_sum(nums: List[int], target: int) -> List[int]that finds the indices of two numbers innumsthat add up totarget. Include a test function verifyingnums=[2, 7, 11, 15], target=9returns[0, 1]. -
Binary Search
Implement
binary_search(nums: List[int], target: int) -> intfor a sorted array. Return the index if found, else -1. Provide a test function verifying cases where the target exists, does not exist, and when the list is empty. -
Valid Parentheses
Write
is_valid_parentheses(s: str) -> boolto validate strings containing '()', '[]', '{}'. Include a test function assertingTruefor'()[]{}'andFalsefor'(]'and'([)]'. -
Merge Sort Implementation
Implement
merge_sort(arr: List[int]) -> List[int]. Include a helper function for the merge step. Write a test function that generates a list of random integers, sorts them using Python's built-in sort, and asserts that your merge sort produces the exact same result. -
Maximum Subarray (Kadane’s)
Write
max_subarray(nums: List[int]) -> intto find the largest sum of a contiguous subarray. Include a test function checking[-2,1,-3,4,-1,2,1,-5,4]returns6(from[4,-1,2,1]). -
Longest Substring Without Repeating Characters
Write
length_of_longest_substring(s: str) -> int. Include a test function asserting that'abcabcbb'returns 3,'bbbbb'returns 1, and'pwwkew'returns 3. -
Reverse Linked List
Define a
ListNodeclass and a functionreverse_list(head: Optional[ListNode]) -> Optional[ListNode]. Include a helper function to convert a list to a linked list and vice versa. Finally, write a test function asserting that[1,2,3,4,5]becomes[5,4,3,2,1]. -
Binary Tree Level Order Traversal
Given a
TreeNodeclass, writelevel_order(root: Optional[TreeNode]) -> List[List[int]]. Include a test function that manually constructs the tree[3,9,20,null,null,15,7]and asserts the output is[[3],[9,20],[15,7]]. -
Climbing Stairs (DP)
Write a function
climb_stairs(n: int) -> intcalculating distinct ways to climbnsteps taking 1 or 2 at a time. Include a test function asserting results forn=2(2 ways) andn=3(3 ways). -
Coin Change Problem
Write
coin_change(coins: List[int], amount: int) -> intto find the minimum coins needed for an amount. Include a test function verifyingcoins=[1, 2, 5], amount=11returns3, andamount=3withcoins=[2]returns-1.
To get the best results from the models on the Ampere platform:
- Clear Instructions: Always specify the input and output types (e.g., Type Hinting).
- Request Tests: Asking the model to generate its own test assertions helps verify the logic immediately.
- Iterative Refinement: If the code fails, feed the error message back to the model to request a fix.
This project is licensed under the MIT License. See the LICENSE file for details.