Search

US-20260126966-A1 - TECHNIQUES FOR MODIFYING PROGRAM CODE USING ARTIFICIAL INTELLIGENCE AGENTS

US20260126966A1US 20260126966 A1US20260126966 A1US 20260126966A1US-20260126966-A1

Abstract

One embodiment of a method for modifying program code includes processing, using a first trained language model, program code to identify one or more modifications to the program code; processing, using a second trained language model, the program code and the one or more modifications to generate a plan for applying the one or more modifications; and processing, using a third trained language model, the program code and the plan to generate a modified program code.

Inventors

  • Sana Damani
  • Siva Kumar Sastry Hari
  • MARK WILLIAM STEPHENSON

Assignees

  • NVIDIA CORPORATION

Dates

Publication Date
20260507
Application Date
20250317

Claims (20)

  1. 1 . A computer-implemented method for modifying program code, the method comprising: processing, using a first trained language model, program code to identify one or more modifications to the program code; processing, using a second trained language model, the program code and the one or more modifications to generate a plan for applying the one or more modifications; and processing, using a third trained language model, the program code and the plan to generate modified program code.
  2. 2 . The computer-implemented method of claim 1 , wherein processing the program code to identify the one or more modifications comprises: processing, using one or more profiling tools, the program code to generate one or more profiling results; inserting, into the program code, one or more comments that indicate the one or more profiling results to generate annotated program code; and processing, using the first trained language model, the annotated program code to identify the one or more modifications.
  3. 3 . The computer-implemented method of claim 1 , wherein processing the program code and the one or more modifications to generate the plan comprises inputting a set of instructions for generating the plan into the second trained language model.
  4. 4 . The computer-implemented method of claim 1 , wherein the plan includes at least one of one or more prompts or one or more instructions for implementing the one or more modifications.
  5. 5 . The computer-implemented method of claim 1 , wherein processing the program code and the plan to generate the modified program code comprises inputting at least one of one or more instructions for generating code or one or more examples into the third trained language model.
  6. 6 . The computer-implemented method of claim 1 , further comprising verifying whether the modified program code satisfies one or more requirements.
  7. 7 . The computer-implemented method of claim 6 , further comprising, in response to not verifying that the modified program code satisfies the one or more requirements, invoking one or more exception handling tools to generate another modified program code.
  8. 8 . The computer-implemented method of claim 1 , further comprising: determining one or more performance metrics of the modified program code relative to the program code; and outputting the one or more performance metrics via a user interface.
  9. 9 . The computer-implemented method of claim 1 , wherein the one or more modifications include at least one of passing one or more compiler options, inserting one or more compiler hints, or one or more intra-kernel or inter-kernel transformations.
  10. 10 . The computer-implemented method of claim 1 , wherein the first trained language model, the second trained language model, and the third trained language model are a same trained language model.
  11. 11 . One or more non-transitory computer-readable media storing instructions that, when executed by at least one processor, cause the at least one processor to perform steps comprising: processing, using a first trained language model, program code to identify one or more modifications to the program code; processing, using a second trained language model, the program code and the one or more modifications to generate a plan for applying the one or more modifications; and processing, using a third trained language model, the program code and the plan to generate modified program code.
  12. 12 . The one or more non-transitory computer-readable media of claim 11 , wherein processing the program code to identify the one or more modifications comprises: processing, using one or more profiling tools, the program code to generate one or more profiling results; inserting, into the program code, one or more comments that indicate the one or more profiling results to generate annotated program code; and processing, using the first trained language model, the annotated program code to identify the one or more modifications.
  13. 13 . The one or more non-transitory computer-readable media of claim 11 , wherein processing the program code and the one or more modifications to generate the plan comprises inputting a set of instructions for generating the plan into the second trained language model.
  14. 14 . The one or more non-transitory computer-readable media of claim 11 , wherein processing the program code and the plan to generate the modified program code comprises inputting at least one of one or more instructions for generating code or one or more examples into the third trained language model.
  15. 15 . The one or more non-transitory computer-readable media of claim 11 , wherein the instructions, when executed by the at least one processor, further cause the at least one processor to perform the step of verifying whether the modified program code satisfies one or more requirements.
  16. 16 . The one or more non-transitory computer-readable media of claim 15 , wherein verifying whether the modified program code satisfies the one or more requirements comprises: compiling the modified program code to generate compiled code; and executing one or more runtime tests during execution of the compiled code.
  17. 17 . The one or more non-transitory computer-readable media of claim 11 , wherein the instructions, when executed by the at least one processor, further cause the at least one processor to perform the steps of: determining one or more performance metrics of the modified program code relative to the program code; and outputting the one or more performance metrics via a user interface.
  18. 18 . The one or more non-transitory computer-readable media of claim 11 , wherein processing the program code and the plan to generate the modified program code comprises invoking one or more patch tools that change the program code.
  19. 19 . The one or more non-transitory computer-readable media of claim 11 , wherein the first trained language model, the second trained language model, and the third trained language model are a same trained large language model.
  20. 20 . A system, comprising: one or more memories storing instructions; and one or more processors that are coupled to the one or more memories and, when executing the instructions, are configured to perform the steps of: processing, using a first trained language model, program code to identify one or more modifications to the program code, processing, using a second trained language model, the program code and the one or more modifications to generate a plan for applying the one or more modifications, and processing, using a third trained language model, the program code and the plan to generate a modified program code.

Description

CROSS-REFERENCE TO RELATED APPLICATIONS This application claims priority benefit of the United States Provisional Patent Application titled, “TECHNIQUES FOR OPTIMIZING CODE USING AGENTIC WORKFLOWS,” filed on Nov. 4, 2024, and having Ser. No. 63/716,188. The subject matter of this related application is hereby incorporated herein by reference. BACKGROUND Field of the Various Embodiments The various embodiments relate generally to computer science, artificial intelligence, and machine learning and, more specifically, to techniques for modifying program code using artificial intelligence agents. Description of the Related Art Program code can oftentimes be optimized to improve the efficiency, performance, and resource utilization of the program code. For example, program code could be optimized to reduce execution time, memory consumption, and/or power usage while maintaining or enhancing the functionality and readability of the program code. As another example, program code could be optimized to execute more efficiently on a particular type of processor, such as a graphics processing unit (GPU). Program code is typically optimized via a largely manual process in which a programmer edits the program code to implement desired optimizations. For example, the programmer could assess reports generated by performance analysis tools that are applied to the program code, evaluate potential optimizations to different portions of the program code, and edit the program code to implement certain optimizations. The manual optimization of program code requires significant expertise and also is typically very labor intensive, time consuming, and error prone. Accordingly, more automated techniques have been developed to perform some optimizations without requiring program code to be edited manually. One conventional approach for automatically optimizing program code uses compilers to make predefined modifications according to rules. Compilers are programs that translate high-level source code written in a user-readable programming language into low-level machine code that can be executed by a computer, which is also referred to as “compiling” the source code. During the compiling process, a compiler can use heuristics in the rules to identify portions of program code that can be optimized, search through different potential modifications to identify beneficial modifications to make, and then modify the portions of program code and/or adjust the compiler settings according to the identified modifications. One drawback of compiler optimization, however, is that compiler optimization typically does not analyze the performance of program code to identify optimizations. Instead, compiler optimization relies on heuristics that may not always identify poorly performing code that needs to be optimized. Searching, by the compiler, through different potential modifications can also take a significant amount of time. In addition, compiler optimization can only make a limited set of predefined modifications to program code according to rules, without being able to make more complex modifications or modifications that are not included in the rules. Another conventional approach for automatically optimizing program code uses a large language model (LLM) to understand the program code and apply optimizations to the program code. LLMs are a type of artificial intelligence (AI) model trained to understand and generate text, which can include program code. One drawback of optimizing program code using an LLM, however, is the LLM needs to be trained using a large amount of example optimizations as training data in order to be able to understand program code and apply similar optimizations. Such a large amount of example optimizations may not be readily available. Even if the large amount of example optimizations were available, training of the LLM using the example optimizations can take considerable time and consume a significant amount of energy. Currently, the LLMs that have been trained to optimize program code are largely limited to changing compiler settings and generating code that compilers are also able to generate. Like compilers, these LLMs are unable to make complex modifications to program code, such as modifications that require reasoning across broad sections of program code. In addition, the LLMs can hallucinate code that appears accurate but is actually incorrect code that cannot execute correctly. As the foregoing illustrates, what is needed in the art are more effective techniques for optimizing program code. SUMMARY One embodiment of the present disclosure sets forth a computer-implemented method for modifying program code. The method includes processing, using a first trained language model, program code to identify one or more modifications to the program code. The method further includes processing, using a second trained language model, the program code and the one or more modifications to generate a plan for applying t