Skip to content

Commit

Permalink
Merge branch 'master' into muse-str-inputs-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
apaniukov authored Jan 31, 2024
2 parents 39e9eb9 + 408f5c1 commit bc17a11
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 45 deletions.
1 change: 1 addition & 0 deletions .ci/azure/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
-DENABLE_CPPLINT=OFF ^
-DENABLE_SAMPLES=OFF ^
-DENABLE_PYTHON=ON ^
-DENABLE_JS=OFF ^
-DCMAKE_C_COMPILER:PATH="$(MSVC_COMPILER_PATH)" ^
-DCMAKE_CXX_COMPILER:PATH="$(MSVC_COMPILER_PATH)" ^
$(OPENVINO_REPO_DIR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pytest .
You can use converted tokenizers in C++ pipelines with prebuild binaries.

1. Download OpenVINO archive distribution for your OS from [here](https://www.intel.com/content/www/us/en/developer/tools/openvino-toolkit/download.html) and extract the archive.
2. Download OpenVINO Tokenizers prebuild libraries from [here](storage.openvinotoolkit.org/repositories/openvino_tokenizers/packages/). To ensure compatibility first three numbers of OpenVINO Tokenizers version should match OpenVINO version and OS.
2. Download OpenVINO Tokenizers prebuild libraries from [here](https://storage.openvinotoolkit.org/repositories/openvino_tokenizers/packages/). To ensure compatibility first three numbers of OpenVINO Tokenizers version should match OpenVINO version and OS.
3. Extract OpenVINO Tokenizers archive into OpenVINO installation directory:
- Windows: `<openvino_dir>\runtime\bin\intel64\Release\`
- MacOS_x86: `<openvino_dir>/runtime/lib/intel64/Release`
Expand Down
7 changes: 4 additions & 3 deletions modules/nvidia_plugin/src/cuda_compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ CompiledModel::CompiledModel(const std::shared_ptr<const ov::Model>& model,
void CompiledModel::init_executor() {
// Default multi-threaded configuration is balanced for throughtput and latency cases and takes into account
// real hardware cores and NUMA nodes.
config_.streams_executor_config_.set_property({ ov::num_streams(ov::streams::Num(memory_pool_->Size())) });
auto streams_executor_config = ov::threading::IStreamsExecutor::Config::make_default_multi_threaded(config_.streams_executor_config_);
streams_executor_config._name = nv_stream_executor_name;
config_.streams_executor_config_ =
ov::threading::IStreamsExecutor::Config{nv_stream_executor_name, static_cast<int>(memory_pool_->Size())};
auto streams_executor_config =
ov::threading::IStreamsExecutor::Config::make_default_multi_threaded(config_.streams_executor_config_);
// As OpenVINO CPU Streams Executor creates some additional threads
// it is better to avoid threads recreateion as some OSs memory allocator can not manage such usage cases
// and memory consumption can be larger than it is expected.
Expand Down
28 changes: 25 additions & 3 deletions modules/nvidia_plugin/src/ops/clamp_cudnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <cuda/float16.hpp>
#include <cuda/runtime.hpp>
#include <cuda_operation_registry.hpp>
#include <ngraph/util.hpp>
#include <type_traits>

#include "converters.hpp"
Expand Down Expand Up @@ -128,13 +127,36 @@ WorkbufferRequest ClampCuDnnOp::GetWorkBufferRequest() const {
return {{el_size, el_size}, {}};
}

namespace {
template <typename T>
T double_to_int(double x, double float_to_int_converter(double)) {
if (!std::is_integral<T>()) {
OPENVINO_THROW("Function double_to_int template parameter must be an integral type.");
}

x = float_to_int_converter(x);

double min_t = static_cast<double>(std::numeric_limits<T>::min());
if (x < min_t) {
return std::numeric_limits<T>::min();
}

double max_t = static_cast<double>(std::numeric_limits<T>::max());
if (x > max_t) {
return std::numeric_limits<T>::max();
}

return static_cast<T>(x);
}
}

template <typename T>
void ClampCuDnnOp::initBuffers(const Buffers& buffers) const {
T max{};
T min{};
if constexpr (std::is_integral<T>()) {
max = ngraph::double_to_int<T>(max_, std::floor);
min = ngraph::double_to_int<T>(min_, std::ceil);
max = double_to_int<T>(max_, std::floor);
min = double_to_int<T>(min_, std::ceil);
} else {
max = static_cast<T>(max_);
min = static_cast<T>(min_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "convolution_components.hpp"

#include "openvino/core/except.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/op/group_conv.hpp"

namespace ov::nvidia_gpu::Convolution::Details {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "openvino/cc/pass/itt.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/core/validation_util.hpp"
#include "openvino/pass/constant_folding.hpp"
#include "openvino/pass/manager.hpp"
#include "openvino/pass/pattern/op/or.hpp"
Expand Down
2 changes: 2 additions & 0 deletions modules/openvino_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ To check the connection manually, use the `Check Connection` button located on t
1. Create a new Python file or open an existing one.
1. Type `def main():` or place the cursor where you'd like code suggestions to be generated.
1. Press the keyboard shortcut `Ctrl+Alt+Space` (`Cmd+Alt+Space` for macOS) or click the `Generate Code Completion` button located in the side panel.
1. You can select the text then generate the related code.
1. You may also right-click on "Generate Inline Code Completion In New Tab" to generate code in a new tab.
1. Use the `Tab` key to accept the entire suggestion or `Ctrl`+`Right Arrow` to accept it word by word. To decline the suggestion, press `Esc`.

You can customize the length of the generated code by adjusting `Max New Tokens` and `Min New Tokens` parameters in the extension settings.
Expand Down
26 changes: 20 additions & 6 deletions modules/openvino_code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions modules/openvino_code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"category": "OpenVINO Code",
"title": "Generate Inline Code Completion"
},
{
"command": "openvinoCode.generateInlineCompletionTab",
"category": "OpenVINO Code",
"title": "Generate Inline Code Completion In New Tab"
},
{
"command": "openvinoCode.generateDocstring",
"category": "OpenVINO Code",
Expand Down Expand Up @@ -159,6 +164,23 @@
"when": "view == openvino-code-side-panel",
"group": "navigation"
}
],
"editor/context": [
{
"command": "openvino-code-completion.toggle",
"group": "openvino-code-completion",
"when": "editorTextFocus && config.openvino-code-completion.showCommandsInContextMenu"
},
{
"command": "openvinoCode.generateInlineCompletion",
"when": "editorFocus",
"group": "openvino-code-completion@1"
},
{
"command": "openvinoCode.generateInlineCompletionTab",
"when": "editorFocus",
"group": "openvino-code-completion@2"
}
]
},
"configuration": [
Expand Down Expand Up @@ -264,6 +286,12 @@
"mac": "ctrl+alt+space",
"when": "editorTextFocus"
},
{
"command": "openvinoCode.generateInlineCompletionTab",
"key": "ctrl+alt+shift+1",
"mac": "ctrl+alt+shift+1",
"when": "editorTextFocus"
},
{
"command": "openvinoCode.stopGeneration",
"key": "escape",
Expand Down
2 changes: 1 addition & 1 deletion modules/openvino_code/side-panel-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"eslint-plugin-react-hooks": "4.6.0",
"eslint-plugin-react-refresh": "0.4.3",
"rollup-plugin-copy": "3.4.0",
"vite": "4.4.5"
"vite": "4.5.2"
}
}
1 change: 1 addition & 0 deletions modules/openvino_code/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const COMMANDS = {
FOCUS_SIDE_PANEL: `${SIDE_PANEL_VIEW_ID}.focus`,
OPEN_SETTINGS: 'openvinoCode.openSettings',
GENERATE_INLINE_COPMLETION: 'openvinoCode.generateInlineCompletion',
GENERATE_INLINE_COPMLETION_TAB: 'openvinoCode.generateInlineCompletionTab',
ACCEPT_INLINE_COMPLETION: 'openvinoCode.acceptInlineCompletion',
GENERATE_DOC_STRING: 'openvinoCode.generateDocstring',
CHECK_CONNECTION: 'openvinoCode.checkConnection',
Expand Down
43 changes: 43 additions & 0 deletions modules/openvino_code/src/inline-completion/completion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { InlineCompletionItem, Position, Range, TextDocument, window } from 'vsc
import { EXTENSION_DISPLAY_NAME } from '../constants';
import { IGenerateRequest, backendService } from '../services/backend.service';
import { extensionState } from '../state';
import * as vscode from 'vscode';
import { getIsGeneralTabActive } from './tab';

const outputChannel = window.createOutputChannel(EXTENSION_DISPLAY_NAME, { log: true });
const logCompletionInput = (input: string): void => outputChannel.append(`Completion input:\n${input}\n\n`);
Expand Down Expand Up @@ -31,6 +33,47 @@ class CompletionService {
if (fillInTheMiddleMode && textAfterCursor.trim()) {
return `${startToken}${textBeforeCursor}${middleToken}${textAfterCursor}${endToken}`;
}

const editor = window.activeTextEditor;
if (!editor) {
return ``; // No open text editor
}

if (getIsGeneralTabActive() === true){
const text = editor.document.getText();
const currentPosition = editor.selection.active;
const selectedText = editor.document.getText(editor.selection);
//const logContent = `Cursor Position: Line ${currentPosition.line + 1}, Character ${currentPosition.character + 1}\nSelected Text: ${selectedText}`;

vscode.workspace.openTextDocument({ content: text }).then(doc => {
vscode.window.showTextDocument(doc, { viewColumn: vscode.ViewColumn.Beside }).then(TabTextEditor => {
const newPosition = new vscode.Position((currentPosition.line + 1), (currentPosition.character + 1));
const newSelection = new vscode.Selection(newPosition, newPosition);
TabTextEditor.selection = newSelection;
},
error => {
// Failed to open the document
console.error('Error:', error);
}
);
},
error => {
// Failed to open the document
console.error('Error:', error);
}
);

if (selectedText !== ``){
return selectedText;
} else {
return textBeforeCursor;
}
}

if (!editor.selection.isEmpty) {
const selectedText = editor.document.getText(editor.selection)
return selectedText;
}
return textBeforeCursor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IExtensionComponent } from '../extension-component.interface';
import { notificationService } from '../services/notification.service';
import { extensionState } from '../state';
import { CommandInlineCompletionItemProvider } from './command-inline-completion-provider';
import { setIsGeneralTabActive } from './tab';

class InlineCompletion implements IExtensionComponent {
private _disposables: Disposable[] = [];
Expand All @@ -14,39 +15,50 @@ class InlineCompletion implements IExtensionComponent {

let commandInlineCompletionDisposable: Disposable;

const generateCommandDisposable = commands.registerCommand(COMMANDS.GENERATE_INLINE_COPMLETION, () => {
if (!extensionState.get('isServerAvailable')) {
notificationService.showServerNotAvailableMessage(extensionState.state);
return;
}
if (extensionState.get('isLoading') && window.activeTextEditor) {
void window.showTextDocument(window.activeTextEditor.document);
return;
}

extensionState.set('isLoading', true);

if (commandInlineCompletionDisposable) {
commandInlineCompletionDisposable.dispose();
}

commandInlineCompletionDisposable = languages.registerInlineCompletionItemProvider(
{ pattern: '**' },
commandInlineCompletionProvider
);

void commandInlineCompletionProvider.triggerCompletion(() => {
commandInlineCompletionDisposable.dispose();
extensionState.set('isLoading', false);
});
});
function generateFunction(): void {
if (!extensionState.get('isServerAvailable')) {
notificationService.showServerNotAvailableMessage(extensionState.state);
return;
}
if (extensionState.get('isLoading') && window.activeTextEditor) {
void window.showTextDocument(window.activeTextEditor.document);
return;
}
extensionState.set('isLoading', true);
if (commandInlineCompletionDisposable) {
commandInlineCompletionDisposable.dispose();
}
commandInlineCompletionDisposable = languages.registerInlineCompletionItemProvider(
{ pattern: '**' },
commandInlineCompletionProvider
);
void commandInlineCompletionProvider.triggerCompletion(() => {
commandInlineCompletionDisposable.dispose();
extensionState.set('isLoading', false);
});
}

const acceptCommandDisposable = commands.registerCommand(COMMANDS.ACCEPT_INLINE_COMPLETION, () => {
void commands.executeCommand('editor.action.inlineSuggest.commit');
});

const generateCommandDisposable = commands.registerCommand(COMMANDS.GENERATE_INLINE_COPMLETION, () => {
setIsGeneralTabActive(false);
generateFunction();
});
context.subscriptions.push(generateCommandDisposable, acceptCommandDisposable);
this._disposables.push(generateCommandDisposable, acceptCommandDisposable);

const generateTabCommandDisposable = commands.registerCommand(COMMANDS.GENERATE_INLINE_COPMLETION_TAB, () => {
setIsGeneralTabActive(true);
generateFunction();
});
context.subscriptions.push(generateTabCommandDisposable, acceptCommandDisposable);
this._disposables.push(generateTabCommandDisposable, acceptCommandDisposable);
}

deactivate(): void {
Expand Down
Loading

0 comments on commit bc17a11

Please sign in to comment.