<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import json

import six
import uuid

from django.conf import settings
from kubernetes import client

from polyaxon_schemas.exceptions import PolyaxonConfigurationError

from polyaxon_k8s import constants as k8s_constants

from spawner.templates import constants


def get_gpu_volume_mounts():
    return [
        client.V1VolumeMount(name='nvidia-bin',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('bin')),
        client.V1VolumeMount(name='nvidia-lib',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('lib')),
        client.V1VolumeMount(name='nvidia-libcuda',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('libcuda')),
    ]


def get_gpu_volumes():
    return [
        client.V1Volume(
            name='nvidia-bin',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('bin'))),
        client.V1Volume(
            name='nvidia-lib',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('lib'))),
        client.V1Volume(
            name='nvidia-libcuda',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('libcuda'))),
    ]


def get_gpu_volumes_def(resources):
    volume_mounts = []
    volumes = []
    if resources and resources.gpu and (settings.DIRS_NVIDIA and settings.MOUNT_PATHS_NVIDIA):
        volume_mounts = get_gpu_volume_mounts()
        volumes = get_gpu_volumes()

    return volume_mounts, volumes


def get_volume_mount(volume, volume_mount=None):
    return client.V1VolumeMount(name=volume, mount_path=volume_mount)


def get_volume(volume, claim_name=None, volume_mount=None):
    if claim_name:
        pv_claim = client.V1PersistentVolumeClaimVolumeSource(claim_name=claim_name)
        return client.V1Volume(name=volume, persistent_volume_claim=pv_claim)
    elif volume_mount:
        return client.V1Volume(
            name=volume,
            host_path=client.V1HostPathVolumeSource(path=volume_mount))
    else:
        empty_dir = client.V1EmptyDirVolumeSource()
        return client.V1Volume(name=volume, empty_dir=empty_dir)


def get_resources(resources):
    """Create resources requirements.

    Args:
        resources: `PodResourcesConfig`

    Return:
        `V1ResourceRequirements`
    """
    limits = {}
    requests = {}
    if resources is None:
        return None
    if resources.cpu:
        if resources.cpu.limits:
            limits['cpu'] = resources.memory.limits
        if resources.cpu.request:
            limits['cpu'] = resources.memory.request

    if resources.cpu:
        if resources.cpu.limits:
            limits['memory'] = '{}Mi'.format(resources.memory.limits)
        if resources.cpu.request:
            limits['memory'] = '{}Mi'.format(resources.memory.request)

    if resources.gpu:
        if resources.gpu.limits:
            limits['alpha.kubernetes.io/nvidia-gpu'] = resources.gpu.limits
        if resources.cpu.request:
            limits['alpha.kubernetes.io/nvidia-gpu'] = resources.gpu.request
    return client.V1ResourceRequirements(limits=limits, requests=requests)


class PodManager(object):<commit_msg>Fix typo gpu instead of cpu<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import json

import six
import uuid

from django.conf import settings
from kubernetes import client

from polyaxon_schemas.exceptions import PolyaxonConfigurationError

from polyaxon_k8s import constants as k8s_constants

from spawner.templates import constants


def get_gpu_volume_mounts():
    return [
        client.V1VolumeMount(name='nvidia-bin',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('bin')),
        client.V1VolumeMount(name='nvidia-lib',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('lib')),
        client.V1VolumeMount(name='nvidia-libcuda',
                             mount_path=settings.MOUNT_PATHS_NVIDIA.get('libcuda')),
    ]


def get_gpu_volumes():
    return [
        client.V1Volume(
            name='nvidia-bin',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('bin'))),
        client.V1Volume(
            name='nvidia-lib',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('lib'))),
        client.V1Volume(
            name='nvidia-libcuda',
            host_path=client.V1HostPathVolumeSource(path=settings.DIRS_NVIDIA.get('libcuda'))),
    ]


def get_gpu_volumes_def(resources):
    volume_mounts = []
    volumes = []
    if resources and resources.gpu and (settings.DIRS_NVIDIA and settings.MOUNT_PATHS_NVIDIA):
        volume_mounts = get_gpu_volume_mounts()
        volumes = get_gpu_volumes()

    return volume_mounts, volumes


def get_volume_mount(volume, volume_mount=None):
    return client.V1VolumeMount(name=volume, mount_path=volume_mount)


def get_volume(volume, claim_name=None, volume_mount=None):
    if claim_name:
        pv_claim = client.V1PersistentVolumeClaimVolumeSource(claim_name=claim_name)
        return client.V1Volume(name=volume, persistent_volume_claim=pv_claim)
    elif volume_mount:
        return client.V1Volume(
            name=volume,
            host_path=client.V1HostPathVolumeSource(path=volume_mount))
    else:
        empty_dir = client.V1EmptyDirVolumeSource()
        return client.V1Volume(name=volume, empty_dir=empty_dir)


def get_resources(resources):
    """Create resources requirements.

    Args:
        resources: `PodResourcesConfig`

    Return:
        `V1ResourceRequirements`
    """
    limits = {}
    requests = {}
    if resources is None:
        return None
    if resources.cpu:
        if resources.cpu.limits:
            limits['cpu'] = resources.memory.limits
        if resources.cpu.request:
            limits['cpu'] = resources.memory.request

    if resources.cpu:
        if resources.cpu.limits:
            limits['memory'] = '{}Mi'.format(resources.memory.limits)
        if resources.cpu.request:
            limits['memory'] = '{}Mi'.format(resources.memory.request)

    if resources.gpu:
        if resources.gpu.limits:
            limits['alpha.kubernetes.io/nvidia-gpu'] = resources.gpu.limits
        if resources.gpu.request:
            limits['alpha.kubernetes.io/nvidia-gpu'] = resources.gpu.request
    return client.V1ResourceRequirements(limits=limits, requests=requests)


class PodManager(object):
{'fraction_non_alphanumeric': 0.10036496350364964, 'fraction_numerical': 0.006386861313868613, 'mean_word_length': 3.020171149144254, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992258', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1945, 'n_words': 322}