Pakistan's First Oracle Blog
How to Implement Tool Use with Command R Plus Model Locally
This video is a simple hands-on tutorial to show how to implement Tool Use with your own data locally by using Cohere Comand R+ model.
Code:
Most Easy Way to Implement RAG with AI Model
This video is a simple hands-on tutorial to show how to implement RAG with your own files locally by using Cohere Comand R+ model.
Code:
Use Hugging Face API Locally for Free Model Access
This video is a hands-on step-by-step tutorial with code to show you how to use hugging face inference API locally for free.
Code:
#pip install huggingface_hub
#export HF_TOKEN="<>"
from huggingface_hub import InferenceClient
import json
repo_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
llm_client = InferenceClient(
model=repo_id,
timeout=120,
)
def call_llm(inference_client: InferenceClient, prompt: str):
response = inference_client.post(
json={
"inputs": prompt,
"parameters": {"max_new_tokens": 200},
"task": "text-generation",
},
)
return json.loads(response.decode())[0]["generated_text"]
response=call_llm(llm_client, "write me a crazy joke")
print (response)
Instant Voice Cloning with AI - Install OpenVoice Locally
This video is a hands-on step-by-step tutorial to install OpenVoice v2 locally to clone voice with AI.
Code: (OpenVoice/demo_part3.ipynb at main · myshell-ai/OpenVoice (github.com))
conda create -n openvoice python=3.9
conda activate openvoice
git clone git@github.com:myshell-ai/OpenVoice.git
cd OpenVoice
pip install -e .
wget https://myshell-public-repo-hosting.s3.amazonaws.com/openvoice/checkpoints_1226.zip
pip install git+https://github.com/myshell-ai/MeloTTS.git
python -m unidic download
import os
import torch
from openvoice import se_extractor
from openvoice.api import ToneColorConverter
ckpt_converter = 'checkpoints_v2/converter'
device = "cuda:0" if torch.cuda.is_available() else "cpu"
output_dir = 'outputs_v2'
tone_color_converter = ToneColorConverter(f'{ckpt_converter}/config.json', device=device)
tone_color_converter.load_ckpt(f'{ckpt_converter}/checkpoint.pth')
os.makedirs(output_dir, exist_ok=True)
reference_speaker = 'resources/example_reference.mp3' # This is the voice you want to clone
target_se, audio_name = se_extractor.get_se(reference_speaker, tone_color_converter, vad=False)
from melo.api import TTS
texts = {
'EN_NEWEST': "Did you ever hear a folk tale about a giant turtle?", # The newest English base speaker model
'EN': "Did you ever hear a folk tale about a giant turtle?",
'ES': "El resplandor del sol acaricia las olas, pintando el cielo con una paleta deslumbrante.",
'FR': "La lueur dorée du soleil caresse les vagues, peignant le ciel d'une palette éblouissante.",
'ZH': "在这次vacation中,我们计划去Paris欣赏埃菲尔铁塔和卢浮宫的美景。",
'JP': "彼は毎朝ジョギングをして体を健康に保っています。",
'KR': "안녕하세요! 오늘은 날씨가 정말 좋네요.",
}
src_path = f'{output_dir}/tmp.wav'
# Speed is adjustable
speed = 1.0
for language, text in texts.items():
model = TTS(language=language, device=device)
speaker_ids = model.hps.data.spk2id
for speaker_key in speaker_ids.keys():
speaker_id = speaker_ids[speaker_key]
speaker_key = speaker_key.lower().replace('_', '-')
source_se = torch.load(f'checkpoints_v2/base_speakers/ses/{speaker_key}.pth', map_location=device)
model.tts_to_file(text, speaker_id, src_path, speed=speed)
save_path = f'{output_dir}/output_v2_{speaker_key}.wav'
# Run the tone color converter
encode_message = "@MyShell"
tone_color_converter.convert(
audio_src_path=src_path,
src_se=source_se,
tgt_se=target_se,
output_path=save_path,
message=encode_message)
Easily Fine-Tune Any Model for Free Locally - No Machine Learning Required
This video is a hands-on step-by-step tutorial to install AutoTrain by hugging face on local system and then fine-tune any model on custom dataset.
$ conda create -n autotrain python=3.10
$ conda activate autotrain
$ pip install autotrain-advanced
$ conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
$ conda install -c "nvidia/label/cuda-12.1.0" cuda-nvcc
$ export HF_TOKEN=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
$ autotrain app --host 0.0.0.0 --port 8000
Dataset Used:
text,label
"This movie was fantastic!",positive
"The food at that restaurant was terrible.",negative
"I love this song!",positive
"The customer service was excellent.",positive
"I couldn't finish reading this book.",negative
How to Quantize a Model with Hugging Face Quanto
This video is a hands-on step-by-step primer about how to quantize any model using Hugging Face Quanto which is a versatile pytorch quantization toolkit.
!pip install transformers==4.35.0
!pip install quanto==0.0.11
!pip install torch==2.1.1
!pip install sentencepiece==0.2.0
model_name = "google/flan-t5-small"
import sentencepiece as spm
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")
input_text = "Meaning of happiness is "
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
from helper import compute_module_sizes
module_sizes = compute_module_sizes(model)
print(f"The model size is {module_sizes[''] * 1e-9} GB")
from quanto import quantize, freeze
import torch
quantize(model, weights=torch.int8, activations=None)
freeze(model)
module_sizes = compute_module_sizes(model)
print(f"The model size is {module_sizes[''] * 1e-9} GB")
input_text = "Meaning of happiness is "
input_ids = tokenizer(input_text, return_tensors="pt").input_ids
outputs = model.generate(input_ids)
print(tokenizer.decode(outputs[0]))
How to do RAG in OpenAI GPT4 Locally with File Search
This video is a hands-on step-by-step primer about how to use RAG with Open AI File Search. OpenAI now supports RAG which means that now you can attach your own files and custom data to OpenAI assistant and talk to your documents with GPT4.
Make sure you have installed latest version of openai on your local system:
pip install openai --upgrade
also make sure to have data.txt in the same folder as your script.
How to Use LLM Function Calling Locally for Free
Function calling in AI simply means that you can call external APIs from within your AI-powered application. Whenever you read that a model can do function calling, it means that it can take a natural language query of user and convert it to a function call. Then you can execute that function call to your API endpoint to get the data, and give it to LLM as additional context and get more grounded latest response as per your application requirement.
How to Fix 401 Authorization Required in Oracle Database for Wallet
I frequently use Oracle wallet for my databases to store certificates. For one site, I started receiving '401 authorization required' error and it seemed that cert was expired. If you are after TLDR; then following shows how we fixed it.
SQL> select utl_http.request('https://dummysite.com',null,'file:/scripts/src/oracle/wallets','XXXXXXXXXX') from dual;
UTL_HTTP.REQUEST('https://dummysite.com',NULL,
--------------------------------------------------------------------------------
401 Authorization Required
SQL> select utl_http.request('https://dummysite.com',null,'file:/d01/oracle/prod2db/10.2.0/appsutil/wallet', null) from dual;
UTL_HTTP.REQUEST('https://dummysite.com',NULL,
--------------------------------------------------------------------------------
401 Authorization Required
All I did was I added the root certificates in the wallet located at /scripts/src/oracle/wallets for fixing this issue.
For details:
First identify which http call from within the application or database was failing:
SQL> select distinct sql_text,sql_id from v$sql where upper(sql_text) like '%UTL%HTTP%';
SQL_TEXT
--------------------------------------------------------------------------------
SQL_ID
-------------
select distinct sql_text,sql_id from v$sql where upper(sql_text) like '%UTL%HTT
P%'
gcgfyfty86c84
SQL> select distinct sql_text,sql_id from v$sqlarea where upper(sql_text) like '%UTL%HTTP%';
SQL_TEXT
--------------------------------------------------------------------------------
SQL_ID
-------------
select distinct sql_text,sql_id from v$sql where upper(sql_text) like '%UTL%HTT
P%'
gcgfyfty86c84
select distinct sql_text,sql_id from v$sqlarea where upper(sql_text) like '%UTL
%HTTP%'
34x064xsfa0dy
and then locate the cert destination and put root certificate from there from your CA.
[oracle@oraapps3 ~]$ cd /scripts/src/oracle/wallets
[oracle@oraapps3 wallets]$ ls -lrt
total 96
-rw-r--r-- 1 oracle oinstall 1115 Aug 22 2023 test2.TESTint.net.cert
-rw-r--r-- 1 oracle oinstall 837 Aug 22 2023 test2
-rw------- 1 oracle oinstall 14765 Jan 25 13:47 ewallet.p12
[oracle@oraapps3 wallets]$ orapki wallet display -wallet .
Enter wallet password:
Requested Certificates:
User Certificates:
Trusted Certificates:
Subject: OU=Class 3 Public Primary Certification Authority,O=VeriSign\, Inc.,C=US
Subject: CN=Entrust.net Certification Authority (2048),OU=(c) 1999 Entrust.net Limited,OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.),O=Entrust.net
Subject: CN=Entrust.net Secure Server Certification Authority,OU=(c) 2000 Entrust.net Limited,OU=www.entrust.net/SSL_CPS incorp. by ref. (limits liab.),O=Entrust.net
AnythingLLM - Any LLM, Any Document, Full Control, Full Privacy, Local, Secure
This video shows how to locally install AnythingLLM to privately and securly and remotely run any LLM with any RAG document. It all runs locally with zero required internet connectivity.
A Way to Identify gc block lost wait event' Wait event in Oracle database
One of the most annoying Oracle wait event is 'gc block lost wait event'. In this post, I am sharing my approach to resolve this issue in an production environment.
First use the netstat command to get the hang of the system:
% netstat --tcp --numeric
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 192.168.128.152:993 192.168.128.120:3853 ESTABLISHED
tcp 0 0 192.168.128.152:143 192.168.128.194:3076 ESTABLISHED
tcp 0 0 192.168.128.152:45771 192.168.128.34:389 TIME_WAIT
tcp 0 0 192.168.128.152:110 192.168.33.123:3521 TIME_WAIT
tcp 0 0 192.168.128.152:25 192.168.231.27:44221 TIME_WAIT
tcp 0 256 192.168.128.152:22 192.168.128.78:47258 ESTABLISHED
If you want to see what (TCP) ports your machine is listening on, use netstat --tcp --listening.
Another useful flag to add to this is --programs which indicates which process is listening on the specified port.
The following example shows a machine listening on ports 80 (www), 443 (https), 22 (ssh), and 25 (smtp);
Code Listing 2: netstat --tcp --listening --programs
# sudo netstat --tcp --listening --programs
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:www *:* LISTEN 28826/apache2
tcp 0 0 *:ssh *:* LISTEN 26604/sshd
tcp 0 0 *:smtp *:* LISTEN 6836/
tcp 0 0 *:https *:* LISTEN 28826/apache2
Note: Using --all displays both connections and listening ports.
The next example uses netstat --route to display the routing table. For most people, this will show one IP and and the gateway address but if you have more than one interface or have multiple IPs assigned to an interface, this command can help troubleshoot network routing problems.
Code Listing 3: netstat --route
% netstat --route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 eth0
The last example of netstat uses the --statistics flag to display networking statistics. Using this flag by itself displays all IP, TCP, UDP, and ICMP connection statistics.
To just show some basic information. For example purposes, only the output from --raw is displayed here.
Combined with the uptime command, this can be used to get an overview of how much traffic your machine is handling on a daily basis.
Code Listing 4: netstat --statistics --route
% netstat --statistics --raw
Ip:
620516640 total packets received
0 forwarded
0 incoming packets discarded
615716262 incoming packets delivered
699594782 requests sent out
5 fragments dropped after timeout
3463529 reassemblies required
636730 packets reassembled ok
5 packet reassembles failed
310797 fragments created
// ICMP statistics truncated
Note: For verbosity, the long names for the various flags were given. Most can be abbreviated to avoid excessive typing (e.g. netstat -tn, netstat -tlp, netstat -r, and netstat -sw).
and now check the AWR report:
1)
Top 10 Foreground Events by Total Wait Time
Top 10 Foreground Events by Total Wait Time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Total Wait Wait % DB Wait
Event Waits Time (sec) Avg(ms) time Class
------------------------------ ----------- ---------- ---------- ------ --------
DB CPU 3691.6 70.3
gc cr block lost 947 511.7 540.31 9.7 Cluster
library cache lock 30,871 422.1 13.67 8.0 Concurre
db file sequential read 252,506 189.6 0.75 3.6 User I/O
gc buffer busy acquire 7,745 183.7 23.72 3.5 Cluster
gc cr block busy 90,856 141.4 1.56 2.7 Cluster
gc cr multi block request 1,768 71.4 40.40 1.4 Cluster
name-service call wait 398 31.7 79.68 .6 Other
gc cr block 2-way 165,758 30.5 0.18 .6 Cluster
log file sync 25,866 20.5 0.79 .4 Commit
Both OS level and AWR level info should tell you if this event is the issue or not and then you can simply look at the sessions contributing to it.
OCI Generative AI Agents
Artificial intelligence (AI) is revolutionizing our interactions with the world, presenting both opportunities and complexities for organizations embracing new AI technologies. Nowhere is this more evident than with generative AI, which integrates knowledge assimilation from various sources to automate tasks and boost human creativity and productivity. This transformative technology empowers organizations to summarize documents, create tables, generate meaningful text, develop code, and synthesize innovative ideas.
Oracle's strategic approach revolves around three AI modalities: infrastructure, models and services, and application integration. Oracle has embedded AI across its cloud applications like CRM, ERP, HCM, CX, and EMR to enhance their functionalities. Similarly, Oracle is introducing generative AI capabilities into its database portfolio, akin to its integration of machine learning (ML) features into Oracle Database service and MySQL HeatWave.
Oracle Cloud Infrastructure (OCI) Generative AI Agents harnesses the potential of large language models (LLMs) and retrieval-augmented generation (RAG), enabling users to query extensive enterprise knowledge bases. Soon, users will access real-time information via natural language interfaces for direct action.
OCI Generative AI Agents RAG service empowers employees to glean insights and answers from disparate sources within the company through natural conversations. The service matches semantic similarities between user queries and documents in a centralized embeddings vector store, consolidating data from diverse corporate systems like ERP, HCM, CX, and data lakes. Users receive results using the most current information, even from dynamic data stores, rather than static reports or outdated indexes.
At the heart of this solution is a large language models or LLMs in short, facilitating natural, conversational interactions with users. You can either use Meta's Llama model or a model from Cohere and that list is going to grow. Think of it as a knowledgeable colleague you can ask business questions in everyday language. This is complemented by an embeddings model that generates embeddings vectors for the corporate document corpus stored in the embeddings vector database.
The retrieval-augmented generation (RAG) system, comprising the vector database, embeddings model, and text generation model, synthesizes responses grounded in retrieved documents. Instead of presenting a list of documents, the AI service delivers natural language responses, supported with references and links to original sources. In the future, users will seamlessly transition from information retrieval to immediate actions like sending emails, contacting customers, or managing orders within the same interface.
Select AI Intro in Oracle Database
Select AI is probably one of the most magical AI feature in Oracle Autonomous database. I have been using it for some time now and it's feels simply like magic.
Select AI represents a cutting-edge feature within the Oracle Autonomous Database, introduced last year, that empowers users to interact with their data using natural language queries. This innovative capability enables individuals to pose questions and receive insights without needing to comprehend the underlying data storage or SQL formulation. By simply directing queries in languages like English, Spanish, French, Portuguese, and more, users can leverage the full potential of their database.
The underlying technology behind Select AI leverages advanced generative AI models, such as those developed by OpenAI or Cohere, which excel at understanding intent and generating SQL code based on natural language prompts. This approach allows developers to extend and build new natural language applications seamlessly within the SQL framework. Select AI streamlines this process by integrating with Oracle SQL, utilizing a standard SELECT statement followed by AI and the natural language query.
One of the remarkable features of Select AI is its conversational capabilities, enhanced with recent updates. Users can engage in a dialogue with the database, posing follow-up questions that build upon previous interactions. This chat history is leveraged by the AI models to provide context-aware responses, resembling a real-life conversation that facilitates deeper exploration of data insights.
Moreover, Select AI is designed to be flexible and adaptable to various business needs. It supports multiple Large Language Models (LLMs) including Cohere and OpenAI, with potential for expansion to include domain-specific models in the future. This pluggable design allows organizations to select the most suitable LLM for their specific use cases, ensuring optimal performance and alignment with business objectives.
With Autonomous Database Select AI, developers can create AI-enabled applications that comprehend users' natural language queries within a conversational context, enabling secure and efficient access to valuable insights from private data sources. This groundbreaking capability marks a significant leap forward in data analytics, harnessing the power of generative AI and natural language processing to democratize access to database insights.
How to Install OpenDevin Locally
This is a step by step easy tutorial to locally install OpenDevin which is an open-source project aiming to replicate Devin, an autonomous AI software engineer who is capable of executing complex engineering tasks and collaborating actively with users on software development projects.
Commands Used:
Pre-requisites:
Update OS:
sudo apt-get update
Install git:
sudo apt-get install git
Install Nodejs:
sudo apt-get install nodejs
Install npm:
sudo apt install npm
Install Rust:
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
Install docker:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Install conda:
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
bash Anaconda3-2022.05-Linux-x86_64.sh
Install uvicorn:
sudo apt install uvicorn
Backend Commands:
git clone https://github.com/OpenDevin/OpenDevin.git
cd OpenDevin
conda create -n opendevin python=3.11
conda activate opendevin
docker ps
docker pull ghcr.io/opendevin/sandbox
which python
python --version
/home/ubuntu/anaconda3/envs/opendevin/bin/python -m pip install pipenv
/home/ubuntu/anaconda3/envs/opendevin/bin/python -m pipenv install -v
/home/ubuntu/anaconda3/envs/opendevin/bin/python -m pipenv shell
uvicorn opendevin.server.listen:app --port 3000
Frontend Commands:
python -m pipenv requirements > requirements.txt && python -m pip install -r requirements.txt
PYTHONPATH=`pwd` /home/ubuntu/anaconda3/envs/opendevin/bin/python opendevin/main.py -d ./workspace/ -i 100 -t "Write a bash script that prints 'hello world'"
Oracle Database Comprehensive Resource Management Strategy
The Oracle Resource Manager is a powerful tool for administrators to maintain system stability, optimize performance, and manage workload prioritization within Oracle Database environments. It provides granular control over resource allocation and ensures that database resources are utilized efficiently to meet business requirements and service level objectives.
Resource Manager is a feature that enables administrators to manage and prioritize system resources such as CPU and memory among different users, applications, sessions, and consumer groups within the database. The Resource Manager allows for the control of resource allocation based on specified policies, ensuring that critical workloads receive adequate resources while preventing resource contention and maintaining overall system performance.
This Oracle script is setting up a comprehensive resource management strategy using Oracle Resource Manager. It defines consumer groups to classify different types of workloads and establishes resource plans with directives to allocate resources and prioritize workload processing based on specified criteria like workload type, time of day, and user groups. This provided Oracle PL/SQL script demonstrates the configuration and utilization of Oracle Resource Manager to manage database resource allocation based on workload characteristics.
PROCEDURE create_consumer_group(
consumer_group IN VARCHAR2,
comment IN VARCHAR2,
cpu_mth IN VARCHAR2 DEFAULT 'ROUND-ROBIN')
The create_consumer_groups.sql script uses this procedure to create the OLTP and batch consumer groups.
CONN sys AS SYSDBA
BEGIN
DBMS_RESOURCE_MANAGER.clear_pending_area;
DBMS_RESOURCE_MANAGER.create_pending_area;
-- Create the consumer groups
DBMS_RESOURCE_MANAGER.create_consumer_group(
consumer_group => 'oltp_consumer_group',
comment => 'OLTP process consumer group.');
DBMS_RESOURCE_MANAGER.create_consumer_group(
consumer_group => 'batch_consumer_group',
comment => 'Batch process consumer group.');
DBMS_RESOURCE_MANAGER.validate_pending_area;
DBMS_RESOURCE_MANAGER.submit_pending_area;
END;
/
BEGIN
DBMS_RESOURCE_MANAGER.clear_pending_area();
DBMS_RESOURCE_MANAGER.create_pending_area();
-- Delete consumer groups.
DBMS_RESOURCE_MANAGER.delete_consumer_group (
consumer_group => 'oltp_consumer_group');
DBMS_RESOURCE_MANAGER.delete_consumer_group (
consumer_group => 'batch_consumer_group');
DBMS_RESOURCE_MANAGER.validate_pending_area;
DBMS_RESOURCE_MANAGER.submit_pending_area();
END;
/
PROCEDURE create_plan (
plan IN VARCHAR2,
comment IN VARCHAR2,
cpu_mth IN VARCHAR2 DEFAULT 'EMPHASIS',
active_sess_pool_mth IN VARCHAR2 DEFAULT 'ACTIVE_SESS_POOL_ABSOLUTE',
parallel_degree_limit_mth IN VARCHAR2 DEFAULT 'PARALLEL_DEGREE_LIMIT_ABSOLUTE',
queueing_mth IN VARCHAR2 DEFAULT 'FIFO_TIMEOUT')
PROCEDURE create_plan_directive (
plan IN VARCHAR2,
group_or_subplan IN VARCHAR2,
comment IN VARCHAR2,
cpu_p1 IN NUMBER DEFAULT NULL,
cpu_p2 IN NUMBER DEFAULT NULL,
cpu_p3 IN NUMBER DEFAULT NULL,
cpu_p4 IN NUMBER DEFAULT NULL,
cpu_p5 IN NUMBER DEFAULT NULL,
cpu_p6 IN NUMBER DEFAULT NULL,
cpu_p7 IN NUMBER DEFAULT NULL,
cpu_p8 IN NUMBER DEFAULT NULL,
active_sess_pool_p1 IN NUMBER DEFAULT NULL,
queueing_p1 IN NUMBER DEFAULT NULL,
parallel_degree_limit_p1 IN NUMBER DEFAULT NULL,
switch_group IN VARCHAR2 DEFAULT NULL,
switch_time IN NUMBER DEFAULT NULL,
switch_estimate IN BOOLEAN DEFAULT FALSE,
max_est_exec_time IN NUMBER DEFAULT NULL,
undo_pool IN NUMBER DEFAULT NULL,
max_idle_time IN NUMBER DEFAULT NULL,
max_idle_blocker_time IN NUMBER DEFAULT NULL,
switch_time_in_call IN NUMBER DEFAULT NULL)
BEGIN
DBMS_RESOURCE_MANAGER.clear_pending_area;
DBMS_RESOURCE_MANAGER.create_pending_area;
-- Create a new plan
DBMS_RESOURCE_MANAGER.create_plan(
plan => 'day_plan',
comment => 'Plan suitable for daytime processing.');
-- Assign consumer groups to plan and define priorities
DBMS_RESOURCE_MANAGER.create_plan_directive (
plan => 'day_plan',
group_or_subplan => 'oltp_consumer_group',
comment => 'Give OLTP processes higher priority - level 1',
cpu_p1 => 80,
switch_group => 'batch_consumer_group',
switch_time => 60);
DBMS_RESOURCE_MANAGER.create_plan_directive (
plan => 'day_plan',
group_or_subplan => 'batch_consumer_group',
comment => 'Give batch processes lower priority - level 2',
cpu_p2 => 100);
DBMS_RESOURCE_MANAGER.create_plan_directive(
plan => 'day_plan',
group_or_subplan => 'OTHER_GROUPS',
comment => 'all other users - level 3',
cpu_p3 => 100);
DBMS_RESOURCE_MANAGER.validate_pending_area;
DBMS_RESOURCE_MANAGER.submit_pending_area;
END;
/
BEGIN
DBMS_RESOURCE_MANAGER.clear_pending_area;
DBMS_RESOURCE_MANAGER.create_pending_area;
-- Create a new plan
DBMS_RESOURCE_MANAGER.create_plan(
plan => 'night_plan',
comment => 'Plan suitable for daytime processing.');
-- Assign consumer groups to plan and define priorities
DBMS_RESOURCE_MANAGER.create_plan_directive (
plan => 'night_plan',
group_or_subplan => 'batch_consumer_group',
comment => 'Give batch processes lower priority - level 2',
cpu_p1 => 80);
DBMS_RESOURCE_MANAGER.create_plan_directive (
plan => 'night_plan',
group_or_subplan => 'oltp_consumer_group',
comment => 'Give OLTP processes higher priority - level 1',
cpu_p2 => 100);
DBMS_RESOURCE_MANAGER.create_plan_directive(
plan => 'night_plan',
group_or_subplan => 'OTHER_GROUPS',
comment => 'all other users - level 3',
cpu_p3 => 100);
DBMS_RESOURCE_MANAGER.validate_pending_area;
DBMS_RESOURCE_MANAGER.submit_pending_area;
END;
/
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'bugdb_plan',
COMMENT => 'Resource plan/method for bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'maildb_plan',
COMMENT => 'Resource plan/method for mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'mydb_plan',
COMMENT => 'Resource plan/method for bug and mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Online_group',
COMMENT => 'Resource consumer group/method for online bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Batch_group',
COMMENT => 'Resource consumer group/method for batch job bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Bug_Maint_group',
COMMENT => 'Resource consumer group/method for users sessions for bug db maint');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Users_group',
COMMENT => 'Resource consumer group/method for mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Postman_group',
COMMENT => 'Resource consumer group/method for mail postman');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Mail_Maint_group',
COMMENT => 'Resource consumer group/method for users sessions for mail db maint');
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Online_group',
COMMENT => 'online bug users sessions at level 1', MGMT_P1 => 80, MGMT_P2=> 0);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Batch_group',
COMMENT => 'batch bug users sessions at level 1', MGMT_P1 => 20, MGMT_P2 => 0,
PARALLEL_DEGREE_LIMIT_P1 => 8);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Bug_Maint_group',
COMMENT => 'bug maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0,
MGMT_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Postman_group',
COMMENT => 'mail postman at level 1', MGMT_P1 => 40, MGMT_P2 => 0);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Users_group',
COMMENT => 'mail users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 80);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Mail_Maint_group',
COMMENT => 'mail maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 20);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0,
MGMT_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'maildb_plan',
COMMENT=> 'all mail users sessions at level 1', MGMT_P1 => 30);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'bugdb_plan',
COMMENT => 'all bug users sessions at level 1', MGMT_P1 => 70);
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/
Temp Tablespace Matters in Oracle
When managing Oracle temporary tablespaces, it's important to prioritize timely data commitment or rollback to release temporary space efficiently.
Additionally, keep an eye out for sessions that remain active without progressing for an extended period; terminating these sessions may be necessary to optimize resource usage. Another crucial consideration is the allocation of small sport segments at the end of a temporary file, which can hinder successful file shrinking. To gain insights into this issue, check the High Water Mark (HWM) of the file to understand its allocation status and potential space usage implications. These practices help maintain the performance and manageability of Oracle temporary tablespaces effectively.
Following are some queries to manage these Temp tablespaces efficiently:
Use this query to get Temp tablespace usage:
SQL> select FILE#, STATUS, Bytes/1024/1024 Size, tf.name Filename, ts.name TS_NAME
from v$tempfile tf , v$tablespace ts where tf.ts# = ts.ts#;
Use this query to get allocated temp space:
SQL> SELECT a.username, a.sid, a.serial#, a.osuser, b.tablespace, b.blocks, c.sql_text
FROM v$session a, v$tempseg_usage b, v$sqlarea
WHERE a.saddr = b.session_addr AND c.address= a.sql_address
AND c.hash_value = a.sql_hash_value ORDER BY b.tablespace, b.blocks;
Use this query to get high water mark of Temp Tablespaces:
SQL>select sum( u.blocks * blk.block_size)/1024/1024 "MB. in sort segments", (hwm.max * blk.block_size)/1024/1024 "HWM"
from v$sort_usage u, (select block_size from dba_tablespaces
where contents = 'TEMPORARY') blk,
(select segblk#+blocks max from
v$sort_usage where segblk# = (select max(segblk#)
from v$sort_usage) ) hwm
group by hwm.max * blk.block_size/1024/1024;
Use this query to shrink the Temp Tablespaces:
SQL> alter tablespace temp shrink space;
How to Create Urdu Hindi AI Model and Dataset from New Dataset
This video is hands on step-by-step tutorial to create a new dataset, an AI model, fine-tune the model on dataset and then push it to hugging face.
Code:
%%capture
import torch
major_version, minor_version = torch.cuda.get_device_capability()
# Must install separately since Colab has torch 2.2.1, which breaks packages
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
if major_version >= 8:
# Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)
!pip install --no-deps packaging ninja flash-attn xformers trl peft accelerate bitsandbytes
else:
# Use this for older GPUs (V100, Tesla T4, RTX 20xx)
!pip install --no-deps xformers trl peft accelerate bitsandbytes
pass
!pip install einops
from unsloth import FastLanguageModel
import torch
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/gemma-7b-bnb-4bit", # Choose ANY! eg teknium/OpenHermes-2.5-Mistral-7B
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
token = " ", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
model = FastLanguageModel.get_peft_model(
model,
r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj",],
lora_alpha = 16,
lora_dropout = 0, # Supports any, but = 0 is optimized
bias = "none", # Supports any, but = "none" is optimized
use_gradient_checkpointing = True,
random_state = 3407,
use_rslora = False, # We support rank stabilized LoRA
loftq_config = None, # And LoftQ
)
alpaca_prompt = """ذیل میں ایک ہدایت ہے جو فلم کے نام کی وضاحت کرتی ہے، اس کے ساتھ ایک ان پٹ بھی ہے جو مزید دستاویزات فراہم کرتا ہے۔ گانے کے بول لکھنے کے لیے ایک لمحہ نکالیں جو فلم کے نام کے معنی سے میل کھاتا ہے۔
### Instruction:
{}
### Input:
{}
### Response:
{}"""
EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN
def formatting_prompts_func(examples):
instructions = examples["urdu_instruction"]
inputs = examples["urdu_input"]
outputs = examples["urdu_output"]
texts = []
for instruction, input, output in zip(instructions, inputs, outputs):
# Must add EOS_TOKEN, otherwise your generation will go on forever!
text = alpaca_prompt.format(instruction, input, output) + EOS_TOKEN
texts.append(text)
return { "text" : texts, }
pass
from datasets import load_dataset
dataset = load_dataset("fahdmirzac/urdu_bollywood_songs_dataset", split = "train")
dataset = dataset.map(formatting_prompts_func, batched = True,)
from huggingface_hub import login
access_token = "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"
login(token=access_token)
from trl import SFTTrainer
from transformers import TrainingArguments
trainer = SFTTrainer(
model = model,
tokenizer = tokenizer,
train_dataset = dataset,
dataset_text_field = "text",
max_seq_length = max_seq_length,
dataset_num_proc = 2,
packing = False, # Can make training 5x faster for short sequences.
args = TrainingArguments(
per_device_train_batch_size = 2,
gradient_accumulation_steps = 4,
warmup_steps = 5,
max_steps = 100,
learning_rate = 2e-4,
fp16 = not torch.cuda.is_bf16_supported(),
bf16 = torch.cuda.is_bf16_supported(),
logging_steps = 1,
optim = "adamw_8bit",
weight_decay = 0.01,
lr_scheduler_type = "linear",
seed = 3407,
output_dir = "outputs",
),
)
trainer_stats = trainer.train()
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
inputs = tokenizer(
[
alpaca_prompt.format(
"دیے گئے فلم کے نام کے بارے میں ایک مختصر گیت کے بول لکھیں۔", # instruction
"کیوں پیار ہو گیا", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 200, use_cache = True)
tokenizer.batch_decode(outputs)
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
inputs = tokenizer(
[
alpaca_prompt.format(
"دیے گئے فلم کے نام کے بارے میں ایک مختصر گیت کے بول لکھیں۔", # instruction
"رنگ", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 200, use_cache = True)
tokenizer.batch_decode(outputs)
model.push_to_hub("fahdmirzac/Gemma_Urdu_Hindi_Bollywood_Songs", token = "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")
Using Claude 3 Haiku Vision with Amazon Bedrock Locally
This video is a hands-on guide as how to use vision features of Anthropic's Claude 3 Haiku AI model with Amazon Bedrock.
Code Used:
Create AI Agent in AWS with Boto3 Code
This video is a step-by-step tutorial with code as how to create Amazon Bedrock AI agents with boto3 in Python to integrate with Lambda.
Code used: Just use any lambda with it of your choice.
Immutable Data Integrity with Oracle's Blockchain Tables
Blockchain tables in Oracle Database implement a unique data organization model, forming chains of insert-only rows. Each row, excluding the first, links back to the previous row using cryptographic hashing. This hashing method leverages row data and the hash of the preceding row to identify any unauthorized modifications through specialized verification procedures. The added capability to store user signatures significantly enhances security against tampering and unauthorized alterations.
Beyond thwarting unauthorized changes initiated by rogue or compromised insiders, blockchain tables boast powerful functionality:
- Identification of illicit modifications made by circumventing Oracle Database protocols.
- Detection of user impersonation and unauthorized data insertions on behalf of another user.
- Safeguarding against data tampering, certifying that all data inserted into the table was done legitimately.
- The chaining mechanism ensures that each row remains linked to its predecessor through cryptographic hashing. Altering any row disrupts this chain, immediately signaling tampering. However, this additional layer of security necessitates increased processing time during commit operations to chain rows effectively.
Let's explore how to create and interact with a blockchain table in Oracle Database through the following example:
-- Creating a blockchain table
SQL> CREATE BLOCKCHAIN TABLE secure_data_table (data_value VARCHAR2(128), sequence_number NUMBER)
NO DROP UNTIL 1 DAYS IDLE
NO DELETE UNTIL 16 DAYS AFTER INSERT
HASHING USING "SHA2_512" VERSION "v1";
Table created.
-- Inserting data into the blockchain table
SQL> INSERT INTO secure_data_table VALUES ('Value1', 1);
1 row created.
SQL> COMMIT;
Commit complete.
-- Querying metadata of the blockchain table
SQL> SELECT column_id, column_name, nullable, hidden_column
FROM all_tab_cols
WHERE table_name LIKE 'SECURE_DATA_%'
ORDER BY column_id;
-- Viewing blockchain table details
SQL> SELECT * FROM dba_blockchain_tables;
In this example, secure_data_table is our blockchain table, ensuring immutable data integrity and providing robust security against unauthorized changes. The SHA2_512 hashing algorithm is employed to maintain the integrity of each chained row, guaranteeing data authenticity and traceability within Oracle Database's secure environment.