AI Model Trainer with EleutherAI/gpt-j-6b for Chameleon Shop Codes

Hits: 14

The Trainer use actually the best chatgpt alternative model on huggingface. Here is the Training notice from Original Source:

This model was trained for 402 billion tokens over 383,500 steps on TPU v3-256 pod. It was trained as an autoregressive language model, using cross-entropy loss to maximize the likelihood of predicting the next token correctly.

https://huggingface.co/EleutherAI/gpt-j-6b#training-procedure

Dataset Links: https://d8devs.com/chameleon-base-and-chameleon-shop-datasets-20230530-1918/



import os
import pandas as pd
import torch
from sklearn.model_selection import train_test_split
from transformers import TrainingArguments, Trainer, AutoModelForCausalLM, AutoTokenizer

checkpoint = "EleutherAI/gpt-j-6b"  # Model checkpoint updated

device = "cuda" if torch.cuda.is_available() else "cpu"

model = AutoModelForCausalLM.from_pretrained(checkpoint, trust_remote_code=True)

tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)
if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token

model = AutoModelForCausalLM.from_pretrained(checkpoint, trust_remote_code=True)
model.to(device)

# Load your data
data = pd.read_csv(os.getcwd() + 'chameleon_base_dataset20230530-1942.csv')

# Prepare your data
# You need to decide how to use your CSV data to create training examples for the model.
# For example, you might concatenate the 'description', 'code', and 'explanation' fields into a single string.
texts = data['description'] + ' ' + data['code'] + ' ' + data['explanation']
labels = data['classname']

# Tokenize your data
inputs = tokenizer(texts.tolist(), padding=True, truncation=True, max_length=512, return_tensors='pt')
inputs['labels'] = torch.tensor(labels.tolist())  # assuming labels are numerical

# Split data into training and validation sets
train_inputs, val_inputs, train_labels, val_labels = train_test_split(inputs, labels, test_size=0.2)

# Define training arguments
training_args = TrainingArguments(
    output_dir='./results',          # output directory
    num_train_epochs=3,              # total number of training epochs
    per_device_train_batch_size=16,  # batch size per device during training
    per_device_eval_batch_size=64,   # batch size for evaluation
    warmup_steps=500,                # number of warmup steps for learning rate scheduler
    weight_decay=0.01,               # strength of weight decay
    logging_dir='./logs',            # directory for storing logs
    load_best_model_at_end=True,     # load the best model when finished training (default metric is loss)
    # but you can specify `metric_for_best_model` argument to change to accuracy, f1, etc.
)

# Initialize our Trainer
trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_inputs,
    eval_dataset=val_inputs,
)

# Training
trainer.train()

# Saving the fine-tuned model
model.save_pretrained('EleutherAI/gpt-j-6b-chameleon')

Dump PHP 8.1 OPCodes using Vulkan Logic Dumper with Bonus

Hits: 189

The VLD a.k.a Vulkan Logic Dumper extension must be installed, we can compiling if from source.

	git clone https://github.com/derickr/vld.git
	cd vld
	phpize
	./configure
	sudo make && sudo make install

with the sudo make && sudo make install command, our vld extension is compilied and copied directly to the php extensions folder. The next step is to active the plugin in the php.ini file

Let’s find our php.ini file.

kzorluoglu@kzorluoglu:~/projects/vld-0.18.0$ php -i | grep 'Loaded Configuration File '
Loaded Configuration File => /etc/php/8.1/cli/php.ini

we found our php.ini file, now let’s active our vld extension with a text editor

sudo vim /etc/php/8.1/cli/php.ini

at the bottom of file, find the ;extension= section. Let’s add extension=vld, and save it.. We are all set!.

and we can dump any php file with this vld.active=1 parameter.

kzorluoglu@kzorluoglu:~/projects/vld-0.18.0$ php -d vld.active=1 test.php
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /home/kzorluoglu/projects/vld-0.18.0/test.php
function name:  (null)
number of ops:  6
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'test'
    4     1        NOP
          2        FAST_CONCAT                                      ~2      !0, '+ist+gut'
          3        ECHO                                                     ~2
    5     4        ECHO                                                     '%0A'
    6     5      > RETURN                                                   1

branch: #  0; line:     3-    6; sop:     0; eop:     5; out0:  -2
path #1: 0,
test ist gut

Bonus: The die() and exit() functions calling the same action thats means: both of them the exact same thing. 🙂

How to develop PHP applications on Local Kubernetes with Helm

Hits: 256

Dont Worry! It is Very Easy.. 🙂

Install the Helm CLI and k3s(/or minikube) as kubernetes before the begin.

  1. Create Project Tree with empty File Content like so:
.
├── Chart.yaml
├── project
│   └── index.php
├── templates
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── pvc.yaml
│   ├── pv.yaml
│   └── service.yaml
└── values.yaml

now let’s fill in the files.

Read more: How to develop PHP applications on Local Kubernetes with Helm

Chart.yaml

apiVersion: v2
name: myfirstlocalphpwithkubernetes
description: A Helm chart for local PHP Development on local Kubernetes

# A chart can be either an 'application' or a 'library' chart.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. 
appVersion: "1.16.0"

project/index.php

<?php

echo "My First local PHP with Kubernetes via Helm";

templates/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-deployment
  labels:
        app: {{ .Release.Name }}-php
spec:
  selector:
    matchLabels:
      app: {{ .Release.Name }}-php
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-php
    spec:
      containers:
      - image: {{ .Values.image.name }}:{{ .Values.image.tag }}
        name: {{ .Release.Name }}-php
        imagePullPolicy: Always
        ports:
          - containerPort: 80
        volumeMounts:
          - name: {{ .Release.Name }}-php-storage
            mountPath: {{ .Values.mountPath }}
      volumes:
        - name: {{ .Release.Name }}-php-storage
          persistentVolumeClaim:
            claimName: {{ .Release.Name }}-pvc-php

templates/ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Release.Name }}-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: {{ .Values.hostname }}
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: {{ .Release.Name }}-php-service
            port:
              number: 80

template/pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name:  pv-{{ .Release.Name }}-php
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: {{ .Values.hostPath }}

template/pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: {{ .Release.Name }}-pvc-php
spec:
    storageClassName: manual
    accessModes:
        - ReadWriteOnce
    resources:
        requests:
            storage: 1Gi

template/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-php-service
spec:
  type: LoadBalancer
  selector:
    app: {{ .Release.Name }}-php
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field

values.yaml

hostname: 'simple-php.local'
mountPath: 'var/www/html/'
hostPath: '/home/projects/myfirstlocalphpwithkubernetes/project'
image:
  name: php
  tag: 8.1-apache

and let’s install with helm

d8dev@d8devs:~/projects/myfirstlocalphpwithkubernetes$ helm install -f values.yaml myfirstlocalphp .

Add hostname (simple-php.local) a.k.a domain in your /etc/hosts with any text editor.

My /etc/hosts looking so;

d8dev@d8devs:~/projects/myfirstlocalphpwithkubernetes$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       simple-php.local
......
.....

And check the domain in your browser with slash ( http://simple-php.local/ )

Enjoy!

Cert-Manager – Kubernetes NGINX Ingress with Cert-Manager

Hits: 282

Install

Cert-manager is easy to install with Helm Package Manager. The first step is add Jetstack repository in our repository and becoming the package info with update

helm repo add jetstack https://charts.jetstack.io
helm repo update

Now we can install Cert-Manager with CRDs into our cluster:

helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true

Cert-manager have also a kubectl plugin to easily manage configs and resources

OS=$(go env GOOS); ARCH=$(go env GOARCH); curl -sSL -o kubectl-cert-manager.tar.gz https://github.com/cert-manager/cert-manager/releases/download/v1.7.2/kubectl-cert_manager-$OS-$ARCH.tar.gz
tar xzf kubectl-cert-manager.tar.gz
sudo mv kubectl-cert_manager /usr/local/bin

Configure for The Let’s Encrypt Certificate

Continue reading “Cert-Manager – Kubernetes NGINX Ingress with Cert-Manager”